2000-02-18 03:38:33 +08:00
|
|
|
/* mmap.cc
|
|
|
|
|
2003-01-15 18:21:23 +08:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2001-01-16 03:42:33 +08:00
|
|
|
#include <unistd.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/mman.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-04-17 01:26:04 +08:00
|
|
|
#include "cygheap.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "pinfo.h"
|
2001-07-11 05:04:14 +08:00
|
|
|
#include "sys/cygwin.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-06-27 21:01:35 +08:00
|
|
|
#define PAGE_CNT(bytes) howmany((bytes),getpagesize())
|
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
|
|
|
|
|
|
|
#define MAP_SET(n) (map_map_[(n)/PGBITS] |= (1L << ((n) % PGBITS)))
|
|
|
|
#define MAP_CLR(n) (map_map_[(n)/PGBITS] &= ~(1L << ((n) % PGBITS)))
|
|
|
|
#define MAP_ISSET(n) (map_map_[(n)/PGBITS] & (1L << ((n) % PGBITS)))
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/*
|
|
|
|
* Simple class used to keep a record of all current
|
|
|
|
* mmap areas in a process. Needed so that
|
|
|
|
* they can be duplicated after a fork().
|
|
|
|
*/
|
|
|
|
|
|
|
|
class mmap_record
|
|
|
|
{
|
|
|
|
private:
|
2001-01-11 20:33:12 +08:00
|
|
|
int fdesc_;
|
2000-02-18 03:38:33 +08:00
|
|
|
HANDLE mapping_handle_;
|
2001-04-17 01:26:04 +08:00
|
|
|
int devtype_;
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD access_mode_;
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t offset_;
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD size_to_map_;
|
2001-01-16 03:42:33 +08:00
|
|
|
caddr_t base_address_;
|
|
|
|
DWORD *map_map_;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
public:
|
2003-04-02 00:11:41 +08:00
|
|
|
mmap_record (int fd, HANDLE h, DWORD ac, _off64_t o, DWORD s, caddr_t b) :
|
2001-04-17 01:26:04 +08:00
|
|
|
fdesc_ (fd),
|
|
|
|
mapping_handle_ (h),
|
|
|
|
devtype_ (0),
|
|
|
|
access_mode_ (ac),
|
|
|
|
offset_ (o),
|
|
|
|
size_to_map_ (s),
|
|
|
|
base_address_ (b),
|
|
|
|
map_map_ (NULL)
|
|
|
|
{
|
2001-09-03 10:13:05 +08:00
|
|
|
if (fd >= 0 && !cygheap->fdtab.not_open (fd))
|
2001-04-19 05:10:15 +08:00
|
|
|
devtype_ = cygheap->fdtab[fd]->get_device ();
|
2001-04-17 01:26:04 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Default Copy constructor/operator=/destructor are ok */
|
|
|
|
|
|
|
|
/* Simple accessors */
|
2001-01-11 20:33:12 +08:00
|
|
|
int get_fd () const { return fdesc_; }
|
2000-02-18 03:38:33 +08:00
|
|
|
HANDLE get_handle () const { return mapping_handle_; }
|
2001-04-17 01:26:04 +08:00
|
|
|
DWORD get_device () const { return devtype_; }
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD get_access () const { return access_mode_; }
|
|
|
|
DWORD get_offset () const { return offset_; }
|
|
|
|
DWORD get_size () const { return size_to_map_; }
|
2001-01-16 03:42:33 +08:00
|
|
|
caddr_t get_address () const { return base_address_; }
|
|
|
|
DWORD *get_map () const { return map_map_; }
|
2003-04-02 00:11:41 +08:00
|
|
|
void alloc_map (_off64_t off, DWORD len);
|
2001-01-16 03:42:33 +08:00
|
|
|
void free_map () { if (map_map_) free (map_map_); }
|
|
|
|
|
|
|
|
DWORD find_empty (DWORD pages);
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t map_map (_off64_t off, DWORD len);
|
2001-01-16 03:42:33 +08:00
|
|
|
BOOL unmap_map (caddr_t addr, DWORD len);
|
2001-02-05 20:36:41 +08:00
|
|
|
void fixup_map (void);
|
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);
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2001-01-16 03:42:33 +08:00
|
|
|
DWORD
|
|
|
|
mmap_record::find_empty (DWORD pages)
|
|
|
|
{
|
|
|
|
DWORD mapped_pages = PAGE_CNT (size_to_map_);
|
|
|
|
DWORD start;
|
|
|
|
|
2001-11-06 04:58:22 +08:00
|
|
|
if (pages > mapped_pages)
|
|
|
|
return (DWORD)-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))
|
|
|
|
{
|
2001-09-03 10:13:05 +08:00
|
|
|
DWORD cnt;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return (DWORD)-1;
|
|
|
|
}
|
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
void
|
2003-04-02 00:11:41 +08:00
|
|
|
mmap_record::alloc_map (_off64_t off, DWORD len)
|
2003-02-08 04:57:30 +08:00
|
|
|
{
|
|
|
|
/* Allocate one bit per page */
|
|
|
|
map_map_ = (DWORD *) calloc (MAPSIZE (PAGE_CNT (size_to_map_)),
|
|
|
|
sizeof (DWORD));
|
|
|
|
if (wincap.virtual_protect_works_on_shared_pages ())
|
|
|
|
{
|
|
|
|
DWORD old_prot;
|
|
|
|
|
|
|
|
off -= offset_;
|
|
|
|
len = PAGE_CNT (len) * getpagesize ();
|
|
|
|
if (off > 0 &&
|
2003-03-10 04:31:07 +08:00
|
|
|
!VirtualProtect (base_address_, off, PAGE_NOACCESS, &old_prot))
|
2003-02-08 04:57:30 +08:00
|
|
|
syscall_printf ("VirtualProtect(%x,%d) failed: %E", base_address_, off);
|
|
|
|
if (off + len < size_to_map_
|
|
|
|
&& !VirtualProtect (base_address_ + off + len,
|
|
|
|
size_to_map_ - len - off,
|
|
|
|
PAGE_NOACCESS, &old_prot))
|
|
|
|
syscall_printf ("VirtualProtect(%x,%d) failed: %E",
|
|
|
|
base_address_ + off + len, size_to_map_ - len - off);
|
|
|
|
off /= getpagesize ();
|
|
|
|
len /= getpagesize ();
|
|
|
|
while (len-- > 0)
|
|
|
|
MAP_SET (off + len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t
|
|
|
|
mmap_record::map_map (_off64_t off, DWORD 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
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
Otherwise it's job is now done by alloc_map(). */
|
2001-01-16 03:42:33 +08:00
|
|
|
DWORD prot, old_prot;
|
|
|
|
switch (access_mode_)
|
|
|
|
{
|
|
|
|
case FILE_MAP_WRITE:
|
|
|
|
prot = PAGE_READWRITE;
|
|
|
|
break;
|
|
|
|
case FILE_MAP_READ:
|
|
|
|
prot = PAGE_READONLY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prot = PAGE_WRITECOPY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-09-24 21:48:07 +08:00
|
|
|
debug_printf ("map_map (fd=%d, off=%D, len=%d)", fdesc_, off, len);
|
2001-01-16 03:42:33 +08:00
|
|
|
len = PAGE_CNT (len);
|
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
if ((off = find_empty (len)) == (DWORD)-1)
|
|
|
|
return 0L;
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (wincap.virtual_protect_works_on_shared_pages ()
|
2003-02-08 04:57:30 +08:00
|
|
|
&& !VirtualProtect (base_address_ + off * getpagesize (),
|
2001-09-03 10:13:05 +08:00
|
|
|
len * getpagesize (), prot, &old_prot))
|
2002-03-14 04:54:57 +08:00
|
|
|
{
|
2002-09-24 22:17:50 +08:00
|
|
|
__seterrno ();
|
2003-04-02 00:11:41 +08:00
|
|
|
return (_off64_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);
|
|
|
|
return off * getpagesize ();
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
mmap_record::unmap_map (caddr_t addr, DWORD len)
|
|
|
|
{
|
|
|
|
DWORD old_prot;
|
|
|
|
DWORD off = addr - base_address_;
|
|
|
|
off /= getpagesize ();
|
|
|
|
len = PAGE_CNT (len);
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (wincap.virtual_protect_works_on_shared_pages ()
|
2001-01-16 03:42:33 +08:00
|
|
|
&& !VirtualProtect (base_address_ + off * getpagesize (),
|
2001-09-03 10:13:05 +08:00
|
|
|
len * getpagesize (), PAGE_NOACCESS, &old_prot))
|
2001-01-16 03:42:33 +08:00
|
|
|
syscall_printf ("-1 = unmap_map (): %E");
|
|
|
|
|
|
|
|
for (; len-- > 0; ++off)
|
|
|
|
MAP_CLR (off);
|
|
|
|
/* Return TRUE if all pages are free'd which may result in unmapping
|
|
|
|
the whole chunk. */
|
2002-09-23 08:31:31 +08:00
|
|
|
for (len = MAPSIZE (PAGE_CNT (size_to_map_)); len > 0; )
|
2001-01-16 03:42:33 +08:00
|
|
|
if (map_map_[--len])
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-02-05 20:36:41 +08:00
|
|
|
void
|
|
|
|
mmap_record::fixup_map ()
|
|
|
|
{
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (!wincap.virtual_protect_works_on_shared_pages ())
|
2001-02-05 20:36:41 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
DWORD prot, old_prot;
|
|
|
|
switch (access_mode_)
|
|
|
|
{
|
|
|
|
case FILE_MAP_WRITE:
|
|
|
|
prot = PAGE_READWRITE;
|
|
|
|
break;
|
|
|
|
case FILE_MAP_READ:
|
|
|
|
prot = PAGE_READONLY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prot = PAGE_WRITECOPY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (DWORD off = PAGE_CNT (size_to_map_); off > 0; --off)
|
2003-02-08 04:57:30 +08:00
|
|
|
VirtualProtect (base_address_ + off * getpagesize (), getpagesize (),
|
|
|
|
MAP_ISSET (off - 1) ? prot : PAGE_NOACCESS, &old_prot);
|
2001-02-05 20:36:41 +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
|
|
|
{
|
|
|
|
if (address < base_address_ || address >= base_address_ + size_to_map_)
|
|
|
|
return 0;
|
|
|
|
DWORD off = (address - base_address_) / getpagesize ();
|
|
|
|
return MAP_ISSET (off);
|
|
|
|
}
|
|
|
|
|
2001-10-14 01:23:35 +08:00
|
|
|
static fhandler_disk_file fh_paging_file;
|
2001-04-17 01:26:04 +08:00
|
|
|
|
|
|
|
fhandler_base *
|
|
|
|
mmap_record::alloc_fh ()
|
|
|
|
{
|
|
|
|
if (get_fd () == -1)
|
|
|
|
{
|
|
|
|
fh_paging_file.set_io_handle (INVALID_HANDLE_VALUE);
|
|
|
|
return &fh_paging_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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. */
|
2002-05-24 13:44:10 +08:00
|
|
|
return cygheap->fdtab.build_fhandler (-1, get_device ());
|
2001-04-17 01:26:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mmap_record::free_fh (fhandler_base *fh)
|
|
|
|
{
|
|
|
|
if (get_fd () != -1)
|
|
|
|
cfree (fh);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
class list {
|
|
|
|
public:
|
|
|
|
mmap_record *recs;
|
|
|
|
int nrecs, maxrecs;
|
|
|
|
int fd;
|
2001-02-09 05:02:36 +08:00
|
|
|
DWORD hash;
|
2000-02-18 03:38:33 +08:00
|
|
|
list ();
|
|
|
|
~list ();
|
2003-04-02 00:11:41 +08:00
|
|
|
mmap_record *add_record (mmap_record r, _off64_t off, DWORD len);
|
2000-02-18 03:38:33 +08:00
|
|
|
void erase (int i);
|
2002-03-14 04:54:57 +08:00
|
|
|
void erase ();
|
2003-04-02 00:11:41 +08:00
|
|
|
mmap_record *match (_off64_t off, DWORD len);
|
2003-07-06 02:59:35 +08:00
|
|
|
long match (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len,
|
|
|
|
long start);
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
list::list ()
|
2001-02-09 05:02:36 +08:00
|
|
|
: nrecs (0), maxrecs (10), fd (0), hash (0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-23 08:31:31 +08:00
|
|
|
recs = (mmap_record *) malloc (10 * sizeof (mmap_record));
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
list::~list ()
|
|
|
|
{
|
2001-01-16 03:42:33 +08:00
|
|
|
for (mmap_record *rec = recs; nrecs-- > 0; ++rec)
|
|
|
|
rec->free_map ();
|
2000-02-18 03:38:33 +08:00
|
|
|
free (recs);
|
|
|
|
}
|
|
|
|
|
2001-01-16 03:42:33 +08:00
|
|
|
mmap_record *
|
2003-04-02 00:11:41 +08:00
|
|
|
list::add_record (mmap_record r, _off64_t off, DWORD len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (nrecs == maxrecs)
|
|
|
|
{
|
|
|
|
maxrecs += 5;
|
|
|
|
recs = (mmap_record *) realloc (recs, maxrecs * sizeof (mmap_record));
|
|
|
|
}
|
2001-01-16 03:42:33 +08:00
|
|
|
recs[nrecs] = r;
|
2003-02-08 04:57:30 +08:00
|
|
|
recs[nrecs].alloc_map (off, len);
|
2001-01-16 03:42:33 +08:00
|
|
|
return recs + nrecs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Used in mmap() */
|
|
|
|
mmap_record *
|
2003-04-02 00:11:41 +08:00
|
|
|
list::match (_off64_t off, DWORD len)
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
|
|
|
if (fd == -1 && !off)
|
|
|
|
{
|
|
|
|
len = PAGE_CNT (len);
|
|
|
|
for (int i = 0; i < nrecs; ++i)
|
|
|
|
if (recs[i].find_empty (len) != (DWORD)-1)
|
|
|
|
return recs + i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < nrecs; ++i)
|
|
|
|
if (off >= recs[i].get_offset ()
|
2002-06-27 21:01:35 +08:00
|
|
|
&& off + len <= recs[i].get_offset ()
|
|
|
|
+ (PAGE_CNT (recs[i].get_size ()) * getpagesize ()))
|
2001-01-16 03:42:33 +08:00
|
|
|
return recs + i;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Used in munmap() */
|
2002-02-26 01:47:51 +08:00
|
|
|
long
|
2003-07-06 02:59:35 +08:00
|
|
|
list::match (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len,
|
|
|
|
_off_t start)
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
2003-07-06 02:59:35 +08:00
|
|
|
caddr_t low, high;
|
|
|
|
|
2001-01-16 03:42:33 +08:00
|
|
|
for (int i = start + 1; i < nrecs; ++i)
|
2003-07-06 02:59:35 +08:00
|
|
|
{
|
|
|
|
low = (addr >= recs[i].get_address ()) ? addr : recs[i].get_address ();
|
|
|
|
high = recs[i].get_address ()
|
|
|
|
+ (PAGE_CNT (recs[i].get_size ()) * getpagesize ());
|
|
|
|
high = (addr + len < high) ? addr + len : high;
|
|
|
|
if (low < high)
|
|
|
|
{
|
|
|
|
m_addr = low;
|
|
|
|
m_len = high - low;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2002-02-26 01:47:51 +08:00
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
list::erase (int i)
|
|
|
|
{
|
2001-01-16 03:42:33 +08:00
|
|
|
recs[i].free_map ();
|
2000-05-12 06:30:45 +08:00
|
|
|
for (; i < nrecs-1; i++)
|
2000-02-18 03:38:33 +08:00
|
|
|
recs[i] = recs[i+1];
|
|
|
|
nrecs--;
|
|
|
|
}
|
|
|
|
|
2002-03-14 04:54:57 +08:00
|
|
|
void
|
|
|
|
list::erase ()
|
|
|
|
{
|
|
|
|
erase (nrecs-1);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
class map {
|
|
|
|
public:
|
|
|
|
list **lists;
|
|
|
|
int nlists, maxlists;
|
|
|
|
map ();
|
|
|
|
~map ();
|
|
|
|
list *get_list_by_fd (int fd);
|
|
|
|
list *add_list (list *l, int fd);
|
|
|
|
void erase (int i);
|
|
|
|
};
|
|
|
|
|
|
|
|
map::map ()
|
|
|
|
{
|
2002-09-23 08:31:31 +08:00
|
|
|
lists = (list **) malloc (10 * sizeof (list *));
|
2000-02-18 03:38:33 +08:00
|
|
|
nlists = 0;
|
|
|
|
maxlists = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
map::~map ()
|
|
|
|
{
|
|
|
|
free (lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
list *
|
|
|
|
map::get_list_by_fd (int fd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<nlists; i++)
|
2001-02-09 05:02:36 +08:00
|
|
|
#if 0 /* The fd isn't sufficient since it could already be another file. */
|
|
|
|
if (lists[i]->fd == fd
|
|
|
|
#else /* so we use the name hash value to identify the file unless
|
2001-09-03 10:13:05 +08:00
|
|
|
it's not an anonymous mapping. */
|
2001-02-09 05:02:36 +08:00
|
|
|
if ((fd == -1 && lists[i]->fd == -1)
|
2001-09-03 10:13:05 +08:00
|
|
|
|| (fd != -1 && lists[i]->hash == cygheap->fdtab[fd]->get_namehash ()))
|
2001-02-09 05:02:36 +08:00
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
return lists[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
list *
|
|
|
|
map::add_list (list *l, int fd)
|
|
|
|
{
|
|
|
|
l->fd = fd;
|
2001-02-09 05:02:36 +08:00
|
|
|
if (fd != -1)
|
2001-04-19 05:10:15 +08:00
|
|
|
l->hash = cygheap->fdtab[fd]->get_namehash ();
|
2000-02-18 03:38:33 +08:00
|
|
|
if (nlists == maxlists)
|
|
|
|
{
|
|
|
|
maxlists += 5;
|
|
|
|
lists = (list **) realloc (lists, maxlists * sizeof (list *));
|
|
|
|
}
|
|
|
|
lists[nlists++] = l;
|
|
|
|
return lists[nlists-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
map::erase (int i)
|
|
|
|
{
|
2000-05-12 06:30:45 +08:00
|
|
|
for (; i < nlists-1; i++)
|
2000-02-18 03:38:33 +08:00
|
|
|
lists[i] = lists[i+1];
|
|
|
|
nlists--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code to keep a record of all mmap'ed areas in a process.
|
|
|
|
* Needed to duplicate tham in a child of fork().
|
|
|
|
* mmap_record classes are kept in an STL list in an STL map, keyed
|
2003-02-08 04:57:30 +08:00
|
|
|
* by file descriptor. This is *NOT* duplicated across a fork(), it
|
2000-02-18 03:38:33 +08:00
|
|
|
* needs to be specially handled by the fork code.
|
|
|
|
*/
|
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
static map *mmapped_areas;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" caddr_t
|
2003-04-02 00:11:41 +08:00
|
|
|
mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, _off64_t off)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-02-26 01:47:51 +08:00
|
|
|
syscall_printf ("addr %x, len %d, prot %x, flags %x, fd %d, off %D",
|
2000-02-18 03:38:33 +08:00
|
|
|
addr, len, prot, flags, fd, off);
|
|
|
|
|
2001-01-16 03:42:33 +08:00
|
|
|
static DWORD granularity;
|
|
|
|
if (!granularity)
|
|
|
|
{
|
|
|
|
SYSTEM_INFO si;
|
|
|
|
GetSystemInfo (&si);
|
|
|
|
granularity = si.dwAllocationGranularity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Error conditions according to SUSv2 */
|
|
|
|
if (off % getpagesize ()
|
2001-01-16 06:18:14 +08:00
|
|
|
|| (!(flags & MAP_SHARED) && !(flags & MAP_PRIVATE))
|
|
|
|
|| ((flags & MAP_SHARED) && (flags & MAP_PRIVATE))
|
2003-07-04 04:53:26 +08:00
|
|
|
|| ((flags & MAP_FIXED) && ((DWORD)addr % getpagesize ()))
|
2001-01-16 03:42:33 +08:00
|
|
|
|| !len)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2001-01-16 06:18:14 +08:00
|
|
|
syscall_printf ("-1 = mmap(): EINVAL");
|
2001-01-16 03:42:33 +08:00
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
SetResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
if (mmapped_areas == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* First mmap call, create STL map */
|
|
|
|
mmapped_areas = new map;
|
2000-11-15 14:27:48 +08:00
|
|
|
if (mmapped_areas == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
syscall_printf ("-1 = mmap(): ENOMEM");
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2001-01-16 03:42:33 +08:00
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & MAP_ANONYMOUS)
|
|
|
|
fd = -1;
|
|
|
|
|
|
|
|
/* Map always in multipliers of `granularity'-sized chunks. */
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t gran_off = off & ~(granularity - 1);
|
2002-09-24 21:48:07 +08:00
|
|
|
DWORD gran_len = howmany (off + len, granularity) * granularity - gran_off;
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2001-10-16 22:04:26 +08:00
|
|
|
fhandler_base *fh;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-01-16 06:18:14 +08:00
|
|
|
if (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)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
syscall_printf ("-1 = mmap(): EBADF");
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2001-01-16 03:42:33 +08:00
|
|
|
return MAP_FAILED;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-10-16 22:04:26 +08:00
|
|
|
fh = cfd;
|
|
|
|
if (fh->get_device () == FH_DISK)
|
2001-09-03 10:13:05 +08:00
|
|
|
{
|
2002-02-26 01:47:51 +08:00
|
|
|
DWORD high;
|
|
|
|
DWORD low = GetFileSize (fh->get_handle (), &high);
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t fsiz = ((_off64_t)high << 32) + low;
|
2003-07-06 02:59:35 +08:00
|
|
|
/* Don't allow mappings beginning beyond EOF since Windows can't
|
|
|
|
handle that POSIX like. FIXME: Still looking for a good idea
|
|
|
|
to allow that nevertheless. */
|
|
|
|
if (gran_off >= fsiz)
|
|
|
|
{
|
|
|
|
set_errno (ENXIO);
|
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
|
|
|
|
"mmap");
|
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
2001-01-16 03:42:33 +08:00
|
|
|
fsiz -= gran_off;
|
|
|
|
if (gran_len > fsiz)
|
|
|
|
gran_len = fsiz;
|
|
|
|
}
|
2001-10-16 22:04:26 +08:00
|
|
|
else if (fh->get_device () == FH_ZERO)
|
2001-01-29 21:39:17 +08:00
|
|
|
/* mmap /dev/zero is like MAP_ANONYMOUS. */
|
2001-09-03 10:13:05 +08:00
|
|
|
fd = -1;
|
2001-01-16 06:18:14 +08:00
|
|
|
}
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
fh_paging_file.set_io_handle (INVALID_HANDLE_VALUE);
|
|
|
|
fh = &fh_paging_file;
|
|
|
|
}
|
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
list *map_list = mmapped_areas->get_list_by_fd (fd);
|
2001-02-09 05:02:36 +08:00
|
|
|
|
|
|
|
/* First check if this mapping matches into the chunk of another
|
2001-04-19 15:44:34 +08:00
|
|
|
already performed mapping. Only valid for MAP_ANON in a special
|
|
|
|
case of MAP_PRIVATE. */
|
2003-02-08 04:57:30 +08:00
|
|
|
if (map_list && fd == -1 && off == 0 && !(flags & MAP_FIXED))
|
2001-01-16 06:18:14 +08:00
|
|
|
{
|
|
|
|
mmap_record *rec;
|
2003-02-08 04:57:30 +08:00
|
|
|
if ((rec = map_list->match (off, len)) != NULL)
|
2001-02-09 05:02:36 +08:00
|
|
|
{
|
2003-04-02 00:11:41 +08:00
|
|
|
if ((off = rec->map_map (off, len)) == (_off64_t)-1)
|
2002-03-14 04:54:57 +08:00
|
|
|
{
|
2002-09-24 22:17:50 +08:00
|
|
|
syscall_printf ("-1 = mmap()");
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK|WRITE_LOCK, "mmap");
|
2002-03-14 04:54:57 +08:00
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
2001-01-16 06:18:14 +08:00
|
|
|
caddr_t ret = rec->get_address () + off;
|
|
|
|
syscall_printf ("%x = mmap() succeeded", ret);
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2001-01-16 06:18:14 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-09-28 06:39:50 +08:00
|
|
|
DWORD access = (prot & PROT_WRITE) ? FILE_MAP_WRITE : FILE_MAP_READ;
|
|
|
|
/* copy-on-write doesn't work at all on 9x using anonymous maps.
|
|
|
|
Workaround: Anonymous mappings always use normal READ or WRITE
|
|
|
|
access and don't use named file mapping.
|
|
|
|
copy-on-write doesn't also work properly on 9x with real files.
|
|
|
|
While the changes are not propagated to the file, they are
|
|
|
|
visible to other processes sharing the same file mapping object.
|
|
|
|
Workaround: Don't use named file mapping. That should work since
|
2001-11-05 14:09:15 +08:00
|
|
|
sharing file mappings only works reliable using named
|
2001-09-28 06:39:50 +08:00
|
|
|
file mapping on 9x.
|
|
|
|
*/
|
|
|
|
if ((flags & MAP_PRIVATE)
|
|
|
|
&& (wincap.has_working_copy_on_write () || fd != -1))
|
|
|
|
access = FILE_MAP_COPY;
|
|
|
|
|
2003-07-04 04:53:26 +08:00
|
|
|
caddr_t base = addr;
|
|
|
|
/* This shifts the base address to the next lower 64K boundary.
|
|
|
|
The offset is re-added when evaluating the return value. */
|
|
|
|
if (base)
|
|
|
|
base -= off - gran_off;
|
|
|
|
|
|
|
|
HANDLE h = fh->mmap (&base, gran_len, access, flags, gran_off);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-05 21:07:02 +08:00
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2000-10-05 21:07:02 +08:00
|
|
|
return MAP_FAILED;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-01-16 03:42:33 +08:00
|
|
|
/* Now we should have a successfully mmapped area.
|
2000-02-18 03:38:33 +08:00
|
|
|
Need to save it so forked children can reproduce it.
|
|
|
|
*/
|
2001-02-05 20:36:41 +08:00
|
|
|
if (fd == -1)
|
|
|
|
gran_len = PAGE_CNT (gran_len) * getpagesize ();
|
2001-01-16 03:42:33 +08:00
|
|
|
mmap_record mmap_rec (fd, h, access, gran_off, gran_len, base);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Get list of mmapped areas for this fd, create a new one if
|
|
|
|
one does not exist yet.
|
|
|
|
*/
|
2003-02-08 04:57:30 +08:00
|
|
|
if (!map_list)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Create a new one */
|
2003-02-08 04:57:30 +08:00
|
|
|
map_list = new list;
|
|
|
|
if (!map_list)
|
2001-09-03 10:13:05 +08:00
|
|
|
{
|
|
|
|
fh->munmap (h, base, gran_len);
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
syscall_printf ("-1 = mmap(): ENOMEM");
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2001-09-03 10:13:05 +08:00
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
2003-02-08 04:57:30 +08:00
|
|
|
map_list = mmapped_areas->add_list (map_list, fd);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert into the list */
|
2003-02-08 04:57:30 +08:00
|
|
|
mmap_record *rec = map_list->add_record (mmap_rec, off, len);
|
2003-02-25 20:46:39 +08:00
|
|
|
caddr_t ret = rec->get_address () + (off - gran_off);
|
2001-01-16 03:42:33 +08:00
|
|
|
syscall_printf ("%x = mmap() succeeded", ret);
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
|
2001-01-16 03:42:33 +08:00
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" caddr_t
|
2003-04-02 00:11:41 +08:00
|
|
|
mmap (caddr_t addr, size_t len, int prot, int flags, int fd, _off_t off)
|
2002-02-26 01:47:51 +08:00
|
|
|
{
|
2003-04-02 00:11:41 +08:00
|
|
|
return mmap64 (addr, len, prot, flags, fd, (_off64_t)off);
|
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
|
2000-02-18 03:38:33 +08:00
|
|
|
munmap (caddr_t addr, size_t len)
|
|
|
|
{
|
|
|
|
syscall_printf ("munmap (addr %x, len %d)", addr, len);
|
|
|
|
|
2003-07-06 02:59:35 +08:00
|
|
|
/* Error conditions according to SUSv3 */
|
|
|
|
if (!addr || ((DWORD)addr % getpagesize ()) || !len
|
|
|
|
|| IsBadReadPtr (addr, len))
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("-1 = munmap(): Invalid parameters");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
|
2000-11-15 14:27:48 +08:00
|
|
|
if (mmapped_areas == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-11-15 14:27:48 +08:00
|
|
|
syscall_printf ("-1 = munmap(): mmapped_areas == NULL");
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
|
2003-07-06 02:59:35 +08:00
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-07-06 02:59:35 +08:00
|
|
|
/* Iterate through the map, unmap pages between addr and addr+len
|
|
|
|
in all maps. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-02-05 20:36:41 +08:00
|
|
|
for (int it = 0; it < mmapped_areas->nlists; ++it)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
list *map_list = mmapped_areas->lists[it];
|
|
|
|
if (map_list)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-02-26 01:47:51 +08:00
|
|
|
long li = -1;
|
2003-07-06 02:59:35 +08:00
|
|
|
caddr_t u_addr;
|
|
|
|
DWORD u_len;
|
|
|
|
|
|
|
|
while ((li = map_list->match(addr, len, u_addr, u_len, li)) >= 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
mmap_record *rec = map_list->recs + li;
|
2003-07-06 02:59:35 +08:00
|
|
|
if (rec->unmap_map (u_addr, u_len))
|
2001-09-03 10:13:05 +08:00
|
|
|
{
|
2001-04-17 01:26:04 +08:00
|
|
|
fhandler_base *fh = rec->alloc_fh ();
|
2001-09-03 10:13:05 +08:00
|
|
|
fh->munmap (rec->get_handle (), addr, len);
|
2001-04-17 01:26:04 +08:00
|
|
|
rec->free_fh (fh);
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Delete the entry. */
|
2003-02-08 04:57:30 +08:00
|
|
|
map_list->erase (li);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
|
2003-07-06 02:59:35 +08:00
|
|
|
syscall_printf ("0 = munmap(): %x", addr);
|
|
|
|
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
|
2000-02-18 03:38:33 +08:00
|
|
|
msync (caddr_t addr, size_t len, int flags)
|
|
|
|
{
|
|
|
|
syscall_printf ("addr = %x, len = %d, flags = %x",
|
|
|
|
addr, len, flags);
|
|
|
|
|
2000-10-05 21:07:02 +08:00
|
|
|
/* However, check flags for validity. */
|
|
|
|
if ((flags & ~(MS_ASYNC | MS_SYNC | MS_INVALIDATE))
|
|
|
|
|| ((flags & MS_ASYNC) && (flags & MS_SYNC)))
|
|
|
|
{
|
|
|
|
syscall_printf ("-1 = msync(): Invalid flags");
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
|
2000-10-05 21:07:02 +08:00
|
|
|
/* Check if a mmap'ed area was ever created */
|
2000-11-15 14:27:48 +08:00
|
|
|
if (mmapped_areas == NULL)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2000-11-15 14:27:48 +08:00
|
|
|
syscall_printf ("-1 = msync(): mmapped_areas == NULL");
|
2000-10-05 21:07:02 +08:00
|
|
|
set_errno (EINVAL);
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
|
2000-10-05 21:07:02 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Iterate through the map, looking for the mmapped area.
|
|
|
|
Error if not found. */
|
|
|
|
|
2001-02-05 20:36:41 +08:00
|
|
|
for (int it = 0; it < mmapped_areas->nlists; ++it)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
list *map_list = mmapped_areas->lists[it];
|
|
|
|
if (map_list != 0)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
for (int li = 0; li < map_list->nrecs; ++li)
|
2001-02-05 20:36:41 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
mmap_record *rec = map_list->recs + li;
|
2002-03-12 04:23:09 +08:00
|
|
|
if (rec->access (addr))
|
2001-02-05 20:36:41 +08:00
|
|
|
{
|
2002-03-12 04:23:09 +08:00
|
|
|
/* Check whole area given by len. */
|
|
|
|
for (DWORD i = getpagesize (); i < len; ++i)
|
|
|
|
if (!rec->access (addr + i))
|
|
|
|
goto invalid_address_range;
|
2001-04-17 01:26:04 +08:00
|
|
|
fhandler_base *fh = rec->alloc_fh ();
|
2001-09-03 10:13:05 +08:00
|
|
|
int ret = fh->msync (rec->get_handle (), addr, len, flags);
|
2001-04-17 01:26:04 +08:00
|
|
|
rec->free_fh (fh);
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2001-09-03 10:13:05 +08:00
|
|
|
if (ret)
|
2000-10-05 21:07:02 +08:00
|
|
|
syscall_printf ("%d = msync(): %E", ret);
|
2001-09-03 10:13:05 +08:00
|
|
|
else
|
2000-10-05 21:07:02 +08:00
|
|
|
syscall_printf ("0 = msync()");
|
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK,
|
|
|
|
"msync");
|
2000-10-05 21:07:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2002-03-12 04:23:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2002-03-12 04:23:09 +08:00
|
|
|
invalid_address_range:
|
2000-10-05 21:07:02 +08:00
|
|
|
/* SUSv2: Return code if indicated memory was not mapped is ENOMEM. */
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
syscall_printf ("-1 = msync(): ENOMEM");
|
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
|
2000-10-05 21:07:02 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
fhandler_base::mmap (caddr_t *addr, size_t len, DWORD access,
|
2003-04-02 00:11:41 +08:00
|
|
|
int flags, _off64_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;
|
|
|
|
}
|
|
|
|
|
2001-01-11 20:33:12 +08:00
|
|
|
BOOL
|
|
|
|
fhandler_base::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset,
|
|
|
|
DWORD size, void *address)
|
|
|
|
{
|
|
|
|
set_errno (ENODEV);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-10-05 21:07:02 +08:00
|
|
|
/* Implementation for disk files. */
|
|
|
|
HANDLE
|
|
|
|
fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
|
2003-04-02 00:11:41 +08:00
|
|
|
int flags, _off64_t off)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
|
|
|
DWORD protect;
|
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
switch (access)
|
|
|
|
{
|
|
|
|
case FILE_MAP_WRITE:
|
2003-03-10 04:31:07 +08:00
|
|
|
protect = PAGE_READWRITE;
|
|
|
|
break;
|
2003-02-08 04:57:30 +08:00
|
|
|
case FILE_MAP_READ:
|
2003-03-10 04:31:07 +08:00
|
|
|
protect = PAGE_READONLY;
|
|
|
|
break;
|
2003-02-08 04:57:30 +08:00
|
|
|
default:
|
|
|
|
protect = PAGE_WRITECOPY;
|
|
|
|
break;
|
|
|
|
}
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2001-07-11 05:04:14 +08:00
|
|
|
HANDLE h;
|
|
|
|
|
|
|
|
/* On 9x/ME try first to open the mapping by name when opening a
|
|
|
|
shared file object. This is needed since 9x/ME only shares
|
|
|
|
objects between processes by name. What a mess... */
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (wincap.share_mmaps_only_by_name ()
|
2001-07-11 05:04:14 +08:00
|
|
|
&& get_handle () != INVALID_HANDLE_VALUE
|
|
|
|
&& !(access & FILE_MAP_COPY))
|
|
|
|
{
|
|
|
|
/* Grrr, the whole stuff is just needed to try to get a reliable
|
2001-09-03 10:13:05 +08:00
|
|
|
mapping of the same file. Even that uprising isn't bullet
|
2001-07-11 05:04:14 +08:00
|
|
|
proof but it does it's best... */
|
|
|
|
char namebuf[MAX_PATH];
|
|
|
|
cygwin_conv_to_full_posix_path (get_name (), namebuf);
|
|
|
|
for (int i = strlen (namebuf) - 1; i >= 0; --i)
|
2001-09-03 10:13:05 +08:00
|
|
|
namebuf[i] = cyg_tolower (namebuf [i]);
|
2001-07-11 05:04:14 +08:00
|
|
|
|
2001-09-28 06:39:50 +08:00
|
|
|
debug_printf ("named sharing");
|
2001-07-11 05:04:14 +08:00
|
|
|
if (!(h = OpenFileMapping (access, TRUE, namebuf)))
|
2002-09-22 11:38:57 +08:00
|
|
|
h = CreateFileMapping (get_handle (), &sec_none, protect, 0, 0, namebuf);
|
2001-07-11 05:04:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
h = CreateFileMapping (get_handle (), &sec_none, protect, 0,
|
|
|
|
get_handle () == INVALID_HANDLE_VALUE ? len : 0,
|
|
|
|
NULL);
|
|
|
|
if (!h)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
syscall_printf ("-1 = mmap(): CreateFileMapping failed with %E");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2002-02-26 01:47:51 +08:00
|
|
|
DWORD high = off >> 32, low = off & 0xffffffff;
|
2003-07-04 04:53:26 +08:00
|
|
|
void *base = NULL;
|
|
|
|
/* If a non-zero address is given, try mapping using the given address first.
|
|
|
|
If it fails and flags is not MAP_FIXED, try again with NULL address. */
|
2003-07-04 17:06:54 +08:00
|
|
|
if (*addr)
|
2003-07-04 04:53:26 +08:00
|
|
|
base = MapViewOfFileEx (h, access, high, low, len, *addr);
|
|
|
|
if (!base && !(flags & MAP_FIXED))
|
|
|
|
base = MapViewOfFileEx (h, access, high, low, len, NULL);
|
|
|
|
debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%D, "
|
|
|
|
"len:%d, addr:%x)", base, h, access, off, len, *addr);
|
2001-02-23 17:49:19 +08:00
|
|
|
if (!base || ((flags & MAP_FIXED) && base != *addr))
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2000-10-08 01:35:36 +08:00
|
|
|
if (!base)
|
2001-09-03 10:13:05 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
syscall_printf ("-1 = mmap(): MapViewOfFileEx failed with %E");
|
|
|
|
}
|
2000-10-08 01:35:36 +08:00
|
|
|
else
|
2001-09-03 10:13:05 +08:00
|
|
|
{
|
2000-10-08 01:35:36 +08:00
|
|
|
set_errno (EINVAL);
|
2001-09-03 10:13:05 +08:00
|
|
|
syscall_printf ("-1 = mmap(): address shift with MAP_FIXED given");
|
|
|
|
}
|
2000-10-05 21:07:02 +08:00
|
|
|
CloseHandle (h);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*addr = (caddr_t) base;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len)
|
|
|
|
{
|
|
|
|
UnmapViewOfFile (addr);
|
|
|
|
CloseHandle (h);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_disk_file::msync (HANDLE h, caddr_t addr, size_t len, int flags)
|
|
|
|
{
|
2000-02-18 03:38:33 +08:00
|
|
|
if (FlushViewOfFile (addr, len) == 0)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 20:33:12 +08:00
|
|
|
BOOL
|
|
|
|
fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset,
|
|
|
|
DWORD size, void *address)
|
|
|
|
{
|
|
|
|
/* Re-create the MapViewOfFileEx call */
|
|
|
|
void *base = MapViewOfFileEx (h, access, 0, offset, size, address);
|
2002-10-21 09:00:58 +08:00
|
|
|
if (base != address)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
(void) VirtualQuery (address, &m, sizeof (m));
|
|
|
|
system_printf ("requested %p != %p mem alloc base %p, state %p, size %d, %E",
|
|
|
|
address, base, m.AllocationBase, m.State, m.RegionSize);
|
|
|
|
}
|
2001-01-11 20:33:12 +08:00
|
|
|
return base == address;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Set memory protection */
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" int
|
2000-02-18 03:38:33 +08:00
|
|
|
mprotect (caddr_t addr, size_t len, int prot)
|
|
|
|
{
|
|
|
|
DWORD old_prot;
|
|
|
|
DWORD new_prot = 0;
|
|
|
|
|
|
|
|
syscall_printf ("mprotect (addr %x, len %d, prot %x)", addr, len, prot);
|
|
|
|
|
2003-01-15 04:40:09 +08:00
|
|
|
if (!wincap.virtual_protect_works_on_shared_pages ()
|
|
|
|
&& addr >= (caddr_t)0x80000000 && addr <= (caddr_t)0xBFFFFFFF)
|
|
|
|
{
|
|
|
|
syscall_printf ("0 = mprotect (9x: No VirtualProtect on shared memory)");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
switch (prot)
|
|
|
|
{
|
|
|
|
case PROT_READ | PROT_WRITE | PROT_EXEC:
|
|
|
|
case PROT_WRITE | PROT_EXEC:
|
|
|
|
new_prot = PAGE_EXECUTE_READWRITE;
|
|
|
|
break;
|
|
|
|
case PROT_READ | PROT_WRITE:
|
|
|
|
case PROT_WRITE:
|
|
|
|
new_prot = PAGE_READWRITE;
|
|
|
|
break;
|
|
|
|
case PROT_READ | PROT_EXEC:
|
|
|
|
new_prot = PAGE_EXECUTE_READ;
|
|
|
|
break;
|
|
|
|
case PROT_READ:
|
|
|
|
new_prot = PAGE_READONLY;
|
2003-02-15 05:15:16 +08:00
|
|
|
break;
|
2003-02-08 04:57:30 +08:00
|
|
|
case PROT_EXEC:
|
|
|
|
new_prot = PAGE_EXECUTE;
|
|
|
|
break;
|
|
|
|
case PROT_NONE:
|
|
|
|
new_prot = PAGE_NOACCESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
syscall_printf ("-1 = mprotect (): invalid prot value");
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (VirtualProtect (addr, len, new_prot, &old_prot) == 0)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
syscall_printf ("-1 = mprotect (): %E");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
syscall_printf ("0 = mprotect ()");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call to re-create all the file mappings in a forked
|
|
|
|
* child. Called from the child in initialization. At this
|
2000-11-15 14:27:48 +08:00
|
|
|
* point we are passed a valid mmapped_areas map, and all the
|
2000-02-18 03:38:33 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int __stdcall
|
2002-03-12 01:57:22 +08:00
|
|
|
fixup_mmaps_after_fork (HANDLE parent)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
debug_printf ("recreate_mmaps_after_fork, mmapped_areas %p", mmapped_areas);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Check if a mmapped area was ever created */
|
2000-11-15 14:27:48 +08:00
|
|
|
if (mmapped_areas == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Iterate through the map */
|
2000-11-15 14:27:48 +08:00
|
|
|
for (int it = 0; it < mmapped_areas->nlists; ++it)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
list *map_list = mmapped_areas->lists[it];
|
|
|
|
if (map_list)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int li;
|
2003-02-08 04:57:30 +08:00
|
|
|
for (li = 0; li < map_list->nrecs; ++li)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
mmap_record *rec = map_list->recs + li;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-01-11 20:33:12 +08:00
|
|
|
debug_printf ("fd %d, h %x, access %x, offset %d, size %d, address %p",
|
2001-02-05 20:36:41 +08:00
|
|
|
rec->get_fd (), rec->get_handle (), rec->get_access (),
|
|
|
|
rec->get_offset (), rec->get_size (), rec->get_address ());
|
2001-01-11 20:33:12 +08:00
|
|
|
|
2001-04-17 01:26:04 +08:00
|
|
|
fhandler_base *fh = rec->alloc_fh ();
|
|
|
|
BOOL ret = fh->fixup_mmap_after_fork (rec->get_handle (),
|
2001-09-03 10:13:05 +08:00
|
|
|
rec->get_access (),
|
|
|
|
rec->get_offset (),
|
|
|
|
rec->get_size (),
|
|
|
|
rec->get_address ());
|
2001-04-17 01:26:04 +08:00
|
|
|
rec->free_fh (fh);
|
|
|
|
|
2001-01-11 20:33:12 +08:00
|
|
|
if (!ret)
|
2002-10-21 09:00:58 +08:00
|
|
|
return -1;
|
2002-03-12 01:57:22 +08:00
|
|
|
if (rec->get_access () == FILE_MAP_COPY)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
2002-03-12 01:57:22 +08:00
|
|
|
for (char *address = rec->get_address ();
|
|
|
|
address < rec->get_address () + rec->get_size ();
|
|
|
|
address += getpagesize ())
|
|
|
|
if (rec->access (address)
|
2002-05-28 09:55:40 +08:00
|
|
|
&& !ReadProcessMemory (parent, address, address,
|
2002-03-12 01:57:22 +08:00
|
|
|
getpagesize (), NULL))
|
|
|
|
{
|
2003-01-15 04:40:09 +08:00
|
|
|
DWORD old_prot;
|
2003-01-16 22:11:10 +08:00
|
|
|
DWORD last_error = GetLastError ();
|
2003-01-15 04:40:09 +08:00
|
|
|
|
2003-01-16 22:11:10 +08:00
|
|
|
if (last_error != ERROR_PARTIAL_COPY
|
|
|
|
&& last_error != ERROR_NOACCESS
|
|
|
|
|| !wincap.virtual_protect_works_on_shared_pages ())
|
2003-01-15 04:40:09 +08:00
|
|
|
{
|
|
|
|
system_printf ("ReadProcessMemory failed for "
|
2003-03-10 04:31:07 +08:00
|
|
|
"MAP_PRIVATE address %p, %E",
|
2003-01-15 04:40:09 +08:00
|
|
|
rec->get_address ());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!VirtualProtectEx (parent,
|
|
|
|
address, getpagesize (),
|
|
|
|
PAGE_READONLY, &old_prot))
|
|
|
|
{
|
|
|
|
system_printf ("VirtualProtectEx failed for "
|
|
|
|
"MAP_PRIVATE address %p, %E",
|
|
|
|
rec->get_address ());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-01-15 05:01:43 +08:00
|
|
|
BOOL ret;
|
|
|
|
DWORD dummy_prot;
|
|
|
|
|
2003-01-15 04:40:09 +08:00
|
|
|
ret = ReadProcessMemory (parent, address, address,
|
|
|
|
getpagesize (), NULL);
|
2003-01-15 05:01:43 +08:00
|
|
|
if (!VirtualProtectEx(parent,
|
|
|
|
address, getpagesize (),
|
|
|
|
old_prot, &dummy_prot))
|
|
|
|
system_printf ("WARNING: VirtualProtectEx to "
|
2003-03-10 04:31:07 +08:00
|
|
|
"return to previous state "
|
2003-01-15 04:40:09 +08:00
|
|
|
"in parent failed for "
|
|
|
|
"MAP_PRIVATE address %p, %E",
|
|
|
|
rec->get_address ());
|
2003-01-15 05:01:43 +08:00
|
|
|
if (!VirtualProtect (address, getpagesize (),
|
|
|
|
old_prot, &dummy_prot))
|
|
|
|
system_printf ("WARNING: VirtualProtect to copy "
|
|
|
|
"protection to child failed for"
|
|
|
|
"MAP_PRIVATE address %p, %E",
|
|
|
|
rec->get_address ());
|
2003-01-15 04:40:09 +08:00
|
|
|
if (!ret)
|
|
|
|
{
|
2003-01-15 05:01:43 +08:00
|
|
|
system_printf ("ReadProcessMemory (2nd try) "
|
|
|
|
"failed for "
|
2003-01-15 04:40:09 +08:00
|
|
|
"MAP_PRIVATE address %p, %E",
|
|
|
|
rec->get_address ());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2002-03-12 01:57:22 +08:00
|
|
|
}
|
2002-05-28 09:55:40 +08:00
|
|
|
}
|
2001-02-05 20:36:41 +08:00
|
|
|
rec->fixup_map ();
|
2000-11-15 14:27:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
debug_printf ("succeeded");
|
|
|
|
return 0;
|
|
|
|
}
|