* mmap.cc (mmap64): Change address types from caddr_t to void *

according to SUSv3.
	(mmap): Ditto.
	(munmap): Ditto.
	(msync): Ditto.
	(mprotect): Ditto.  Move to before the fhandler methods.
	* include/sys/mman.h: Change prototypes accordingly.
This commit is contained in:
Corinna Vinschen 2003-09-09 09:41:18 +00:00
parent 3ef50005c7
commit 807dfb3d4a
3 changed files with 83 additions and 72 deletions

View File

@ -1,3 +1,13 @@
2003-09-09 Corinna Vinschen <corinna@vinschen.de>
* mmap.cc (mmap64): Change address types from caddr_t to void *
according to SUSv3.
(mmap): Ditto.
(munmap): Ditto.
(msync): Ditto.
(mprotect): Ditto. Move to before the fhandler methods.
* include/sys/mman.h: Change prototypes accordingly.
2003-09-08 Christopher Faylor <cgf@redhat.com> 2003-09-08 Christopher Faylor <cgf@redhat.com>
* dcrt0.cc (dlL_crt0_1): Set __argc_safe after __argc is absolutely * dcrt0.cc (dlL_crt0_1): Set __argc_safe after __argc is absolutely

View File

@ -41,11 +41,11 @@ extern "C" {
#define MS_INVALIDATE 4 #define MS_INVALIDATE 4
#ifndef __INSIDE_CYGWIN__ #ifndef __INSIDE_CYGWIN__
extern caddr_t mmap (caddr_t __addr, size_t __len, int __prot, int __flags, int __fd, off_t __off); extern void *mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, off_t __off);
#endif #endif
extern int munmap (caddr_t __addr, size_t __len); extern int munmap (void *__addr, size_t __len);
extern int mprotect (caddr_t __addr, size_t __len, int __prot); extern int mprotect (void *__addr, size_t __len, int __prot);
extern int msync (caddr_t __addr, size_t __len, int __flags); extern int msync (void *__addr, size_t __len, int __flags);
#ifdef __cplusplus #ifdef __cplusplus
}; };

View File

@ -448,8 +448,8 @@ map::del_list (int i)
} }
} }
extern "C" caddr_t extern "C" void *
mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, _off64_t off) mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
{ {
syscall_printf ("addr %x, len %u, prot %x, flags %x, fd %d, off %D", syscall_printf ("addr %x, len %u, prot %x, flags %x, fd %d, off %D",
addr, len, prot, flags, fd, off); addr, len, prot, flags, fd, off);
@ -576,7 +576,7 @@ mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, _off64_t off)
&& (wincap.has_working_copy_on_write () || fd != -1)) && (wincap.has_working_copy_on_write () || fd != -1))
access = FILE_MAP_COPY; access = FILE_MAP_COPY;
caddr_t base = addr; caddr_t base = (caddr_t)addr;
/* This shifts the base address to the next lower 64K boundary. /* This shifts the base address to the next lower 64K boundary.
The offset is re-added when evaluating the return value. */ The offset is re-added when evaluating the return value. */
if (base) if (base)
@ -631,8 +631,8 @@ mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, _off64_t off)
return ret; return ret;
} }
extern "C" caddr_t extern "C" void *
mmap (caddr_t addr, size_t len, int prot, int flags, int fd, _off_t off) mmap (void *addr, size_t len, int prot, int flags, int fd, _off_t off)
{ {
return mmap64 (addr, len, prot, flags, fd, (_off64_t)off); return mmap64 (addr, len, prot, flags, fd, (_off64_t)off);
} }
@ -640,7 +640,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, _off_t off)
/* munmap () removes all mmapped pages between addr and addr+len. */ /* munmap () removes all mmapped pages between addr and addr+len. */
extern "C" int extern "C" int
munmap (caddr_t addr, size_t len) munmap (void *addr, size_t len)
{ {
syscall_printf ("munmap (addr %x, len %u)", addr, len); syscall_printf ("munmap (addr %x, len %u)", addr, len);
@ -672,7 +672,7 @@ munmap (caddr_t addr, size_t len)
caddr_t u_addr; caddr_t u_addr;
DWORD u_len; DWORD u_len;
while ((record_idx = map_list->search_record(addr, len, u_addr, while ((record_idx = map_list->search_record((caddr_t)addr, len, u_addr,
u_len, record_idx)) >= 0) u_len, record_idx)) >= 0)
{ {
mmap_record *rec = map_list->get_record (record_idx); mmap_record *rec = map_list->get_record (record_idx);
@ -680,7 +680,7 @@ munmap (caddr_t addr, size_t len)
{ {
/* The whole record has been unmapped, so... */ /* The whole record has been unmapped, so... */
fhandler_base *fh = rec->alloc_fh (); fhandler_base *fh = rec->alloc_fh ();
fh->munmap (rec->get_handle (), addr, len); fh->munmap (rec->get_handle (), (caddr_t)addr, len);
rec->free_fh (fh); rec->free_fh (fh);
/* ...delete the record. */ /* ...delete the record. */
@ -703,7 +703,7 @@ munmap (caddr_t addr, size_t len)
/* Sync file with memory. Ignore flags for now. */ /* Sync file with memory. Ignore flags for now. */
extern "C" int extern "C" int
msync (caddr_t addr, size_t len, int flags) msync (void *addr, size_t len, int flags)
{ {
syscall_printf ("addr = %x, len = %u, flags = %x", syscall_printf ("addr = %x, len = %u, flags = %x",
addr, len, flags); addr, len, flags);
@ -740,14 +740,15 @@ msync (caddr_t addr, size_t len, int flags)
(rec = map_list->get_record (record_idx)); (rec = map_list->get_record (record_idx));
++record_idx) ++record_idx)
{ {
if (rec->access (addr)) if (rec->access ((caddr_t)addr))
{ {
/* Check whole area given by len. */ /* Check whole area given by len. */
for (DWORD i = getpagesize (); i < len; ++i) for (DWORD i = getpagesize (); i < len; ++i)
if (!rec->access (addr + i)) if (!rec->access ((caddr_t)addr + i))
goto invalid_address_range; goto invalid_address_range;
fhandler_base *fh = rec->alloc_fh (); fhandler_base *fh = rec->alloc_fh ();
int ret = fh->msync (rec->get_handle (), addr, len, flags); int ret = fh->msync (rec->get_handle (), (caddr_t)addr, len,
flags);
rec->free_fh (fh); rec->free_fh (fh);
if (ret) if (ret)
@ -771,6 +772,62 @@ invalid_address_range:
return -1; return -1;
} }
/* Set memory protection */
extern "C" int
mprotect (void *addr, size_t len, int prot)
{
DWORD old_prot;
DWORD new_prot = 0;
syscall_printf ("mprotect (addr %x, len %u, prot %x)", addr, len, prot);
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;
}
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;
break;
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;
}
if (VirtualProtect (addr, len, new_prot, &old_prot) == 0)
{
__seterrno ();
syscall_printf ("-1 = mprotect (): %E");
return -1;
}
syscall_printf ("0 = mprotect ()");
return 0;
}
/* /*
* Base implementation: * Base implementation:
* *
@ -930,62 +987,6 @@ fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset,
return base == address; return base == address;
} }
/* Set memory protection */
extern "C" int
mprotect (caddr_t addr, size_t len, int prot)
{
DWORD old_prot;
DWORD new_prot = 0;
syscall_printf ("mprotect (addr %x, len %u, prot %x)", addr, len, prot);
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;
}
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;
break;
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;
}
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 * Call to re-create all the file mappings in a forked
* child. Called from the child in initialization. At this * child. Called from the child in initialization. At this