* mmap.cc (mmap_record::map_map): Return -1 if VirtualProtect fails.

(list::erase): New method with no argument.  Erase latest record
	added.
	(mmap64): Fail if map_map() fails.
This commit is contained in:
Corinna Vinschen 2002-03-13 20:54:57 +00:00
parent 5289f34254
commit bbe0913914
2 changed files with 38 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2002-03-13 Corinna Vinschen <corina@vinschen.de>
* mmap.cc (mmap_record::map_map): Return -1 if VirtualProtect fails.
(list::erase): New method with no argument. Erase latest record
added.
(mmap64): Fail if map_map() fails.
2002-03-12 Corinna Vinschen <corina@vinschen.de> 2002-03-12 Corinna Vinschen <corina@vinschen.de>
* sysconf.cc (sysconf): Fix condition. * sysconf.cc (sysconf): Fix condition.

View File

@ -151,7 +151,10 @@ mmap_record::map_map (__off64_t off, DWORD len)
if (wincap.virtual_protect_works_on_shared_pages () if (wincap.virtual_protect_works_on_shared_pages ()
&& !VirtualProtect (base_address_ + off * getpagesize (), && !VirtualProtect (base_address_ + off * getpagesize (),
len * getpagesize (), prot, &old_prot)) len * getpagesize (), prot, &old_prot))
syscall_printf ("-1 = map_map (): %E"); {
debug_printf ("-1 = map_map (): %E");
return (__off64_t)-1;
}
while (len-- > 0) while (len-- > 0)
MAP_SET (off + len); MAP_SET (off + len);
@ -164,7 +167,10 @@ mmap_record::map_map (__off64_t off, DWORD len)
if (wincap.virtual_protect_works_on_shared_pages () if (wincap.virtual_protect_works_on_shared_pages ()
&& !VirtualProtect (base_address_ + start * getpagesize (), && !VirtualProtect (base_address_ + start * getpagesize (),
len * getpagesize (), prot, &old_prot)) len * getpagesize (), prot, &old_prot))
syscall_printf ("-1 = map_map (): %E"); {
debug_printf ("-1 = map_map (): %E");
return (__off64_t)-1;
}
for (; len-- > 0; ++start) for (; len-- > 0; ++start)
MAP_SET (start); MAP_SET (start);
@ -265,6 +271,7 @@ public:
~list (); ~list ();
mmap_record *add_record (mmap_record r); mmap_record *add_record (mmap_record r);
void erase (int i); void erase (int i);
void erase ();
mmap_record *match (__off64_t off, DWORD len); mmap_record *match (__off64_t off, DWORD len);
long match (caddr_t addr, DWORD len, long start); long match (caddr_t addr, DWORD len, long start);
}; };
@ -336,6 +343,12 @@ list::erase (int i)
nrecs--; nrecs--;
} }
void
list::erase ()
{
erase (nrecs-1);
}
class map { class map {
public: public:
list **lists; list **lists;
@ -501,7 +514,13 @@ mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, __off64_t off)
mmap_record *rec; mmap_record *rec;
if ((rec = l->match (off, len)) != NULL) if ((rec = l->match (off, len)) != NULL)
{ {
off = rec->map_map (off, len); if ((off = rec->map_map (off, len)) == (__off64_t)-1)
{
set_errno (ENOMEM);
syscall_printf ("-1 = mmap(): ENOMEM");
ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK|WRITE_LOCK, "mmap");
return MAP_FAILED;
}
caddr_t ret = rec->get_address () + off; caddr_t ret = rec->get_address () + off;
syscall_printf ("%x = mmap() succeeded", ret); syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
@ -559,7 +578,15 @@ mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, __off64_t off)
/* Insert into the list */ /* Insert into the list */
mmap_record *rec = l->add_record (mmap_rec); mmap_record *rec = l->add_record (mmap_rec);
off = rec->map_map (off, len); if ((off = rec->map_map (off, len)) == (__off64_t)-1)
{
fh->munmap (h, base, gran_len);
l->erase ();
set_errno (ENOMEM);
syscall_printf ("-1 = mmap(): ENOMEM");
ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED;
}
caddr_t ret = rec->get_address () + off; caddr_t ret = rec->get_address () + off;
syscall_printf ("%x = mmap() succeeded", ret); syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");