newlib/winsup/cygwin/mmap.cc

1328 lines
36 KiB
C++
Raw Normal View History

2000-02-17 20:38:33 +01:00
/* mmap.cc
2005-02-20 05:25:33 +01:00
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005
Red Hat, Inc.
2000-02-17 20:38:33 +01: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. */
#include "winsup.h"
#include <unistd.h>
2000-02-17 20:38:33 +01:00
#include <stdlib.h>
#include <stddef.h>
#include <sys/mman.h>
#include "cygerrno.h"
#include "security.h"
Add "path.h" include throughout, where needed. Use new path_conv methods and operators to simplify testing for directory and attributes, throughout. * path.h (path_conv::exists): New method. (path_conv::has_attribute): Ditto. (path_conv::isdir): Ditto. (path_conv::DWORD &): New operator. (path_conv::int &): Ditto. * dir.cc (rmdir): Eliminate a goto. * dtable.cc (dtable::build_fhandler): Accept opt and suffix info for path_conv.check. Return fh == NULL on path_conv error. Pass unit to set_name as appropriate. (dtable::reset_unix_path_name): New method. * dtable.h (dtable): Declare new method. Reflect arg changes to build_fhandler. * fhandler.cc (fhandler_disk_dummy_name): Eliminate. (fhandler_base::set_name): Expect paths to be NULL. Build unix_path_name from win32_path_name when it is a device. (fhandler_base::reset_unix_path_name): New method. (fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER and reading a directory. (fhandler_disk_file::fstat): Don't call stat_dev since we should now never be calling fhandler_disk_file methods with devices. (fhandler_base::fhandler_base): Clear {unix,win32}_path_name. (fhandler_base::~fhandler_base): Always free {unix,win32}_path_name. (fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge. (fhandler_disk_file::open): Ditto. * fhandler.h (fhandler_base::no_free_names): Eliminate. (fhandler_base::set_no_free_names): Ditto. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set unix_path_name here. * path.cc (fchdir): Lock fd table throughout. Use new dtable::reset_unix_path_name method to reset path. * syscalls.cc (stat_worker): Reorganize to always call fstat method. Pass path_conv method to fhandler_*::open. (chroot): Elminate a goto.
2001-10-01 06:10:07 +02: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 02:37:18 +02:00
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include "pinfo.h"
#include "sys/cygwin.h"
#include "ntdll.h"
2000-02-17 20:38:33 +01:00
#define PAGE_CNT(bytes) howmany((bytes),getpagesize())
#define PGBITS (sizeof (DWORD)*8)
#define MAPSIZE(pages) howmany ((pages), PGBITS)
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02: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)))
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
/* Used for accessing the page file (anonymous mmaps). */
static fhandler_disk_file fh_paging_file;
/* 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().
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
The class structure:
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
One member of class map per process, global variable mmapped_areas.
Contains a dynamic class list array. Each list entry represents all
mapping to a file, keyed by file descriptor and file name hash.
Each list entry contains a dynamic class mmap_record array. Each
mmap_record represents exactly one mapping. For each mapping, there's
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-17 20:38:33 +01:00
class mmap_record
{
private:
int fdesc_;
2000-02-17 20:38:33 +01:00
HANDLE mapping_handle_;
DWORD access_mode_;
int flags_;
_off64_t offset_;
2000-02-17 20:38:33 +01:00
DWORD size_to_map_;
caddr_t base_address_;
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
DWORD *page_map_;
* 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 02:37:18 +02:00
device dev;
2000-02-17 20:38:33 +01:00
public:
mmap_record (int fd, HANDLE h, DWORD ac, int f, _off64_t o, DWORD s,
caddr_t b) :
fdesc_ (fd),
mapping_handle_ (h),
access_mode_ (ac),
flags_ (f),
offset_ (o),
size_to_map_ (s),
base_address_ (b),
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
page_map_ (NULL)
{
* 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 02:37:18 +02:00
dev.devn = 0;
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 02:37:18 +02:00
dev = cygheap->fdtab[fd]->dev ();
}
2000-02-17 20:38:33 +01:00
int get_fd () const { return fdesc_; }
2000-02-17 20:38:33 +01:00
HANDLE get_handle () const { return mapping_handle_; }
* 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 02:37:18 +02:00
device& get_device () { return dev; }
2000-02-17 20:38:33 +01:00
DWORD get_access () const { return access_mode_; }
DWORD get_flags () const { return flags_; }
_off64_t get_offset () const { return offset_; }
2000-02-17 20:38:33 +01:00
DWORD get_size () const { return size_to_map_; }
caddr_t get_address () const { return base_address_; }
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
bool alloc_page_map (_off64_t off, DWORD len);
void free_page_map () { if (page_map_) cfree (page_map_); }
void fixup_page_map (void);
DWORD find_unused_pages (DWORD pages);
_off64_t map_pages (_off64_t off, DWORD len);
bool map_pages (caddr_t addr, DWORD len);
bool unmap_pages (caddr_t addr, DWORD len);
int access (caddr_t address);
fhandler_base *alloc_fh ();
void free_fh (fhandler_base *fh);
2000-02-17 20:38:33 +01:00
};
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
class list
{
private:
mmap_record *recs;
int nrecs, maxrecs;
int fd;
DWORD hash;
public:
int get_fd () const { return fd; }
DWORD get_hash () const { return hash; }
mmap_record *get_record (int i) { return i >= nrecs ? NULL : recs + i; }
void set (int nfd);
mmap_record *add_record (mmap_record r, _off64_t off, DWORD len);
bool del_record (int i);
void free_recs () { if (recs) cfree (recs); }
mmap_record *search_record (_off64_t off, DWORD len);
long search_record (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len,
long start);
};
class map
{
private:
list *lists;
int nlists, maxlists;
caddr_t next_anon_addr;
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
public:
list *get_list (int i) { return i >= nlists ? NULL : lists + i; }
list *get_list_by_fd (int fd);
list *add_list (int fd);
void del_list (int i);
caddr_t get_next_anon_addr () { return next_anon_addr; }
void set_next_anon_addr (caddr_t addr) { next_anon_addr = addr; }
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
};
/* This is the global map structure pointer. It's allocated once on the
first call to mmap64(). */
static map *mmapped_areas;
DWORD
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record::find_unused_pages (DWORD pages)
{
DWORD mapped_pages = PAGE_CNT (size_to_map_);
DWORD start;
if (pages > mapped_pages)
return (DWORD)-1;
for (start = 0; start <= mapped_pages - pages; ++start)
if (!MAP_ISSET (start))
{
DWORD cnt;
for (cnt = 0; cnt < pages; ++cnt)
if (MAP_ISSET (start + cnt))
break;
if (cnt >= pages)
return start;
}
return (DWORD)-1;
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
bool
mmap_record::alloc_page_map (_off64_t off, DWORD len)
{
/* Allocate one bit per page */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (!(page_map_ = (DWORD *) ccalloc (HEAP_MMAP,
MAPSIZE (PAGE_CNT (size_to_map_)),
sizeof (DWORD))))
return false;
off -= offset_;
len = PAGE_CNT (len);
if (wincap.virtual_protect_works_on_shared_pages ())
{
DWORD old_prot;
DWORD vlen = len * getpagesize ();
if (off > 0 &&
2003-03-09 21:31:07 +01:00
!VirtualProtect (base_address_, off, PAGE_NOACCESS, &old_prot))
syscall_printf ("VirtualProtect(%x,%D) failed, %E", base_address_, off);
if (off + vlen < size_to_map_
&& !VirtualProtect (base_address_ + off + vlen,
size_to_map_ - vlen - off,
PAGE_NOACCESS, &old_prot))
syscall_printf ("VirtualProtect(%x,%D) failed, %E",
base_address_ + off + vlen, size_to_map_ - vlen - off);
}
off /= getpagesize ();
while (len-- > 0)
MAP_SET (off + len);
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
return true;
}
_off64_t
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record::map_pages (_off64_t off, DWORD len)
{
/* 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-09 21:31:07 +01:00
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
Otherwise it's job is now done by alloc_page_map(). */
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;
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
debug_printf ("map_pages (fd=%d, off=%D, len=%u)", fdesc_, off, len);
len = PAGE_CNT (len);
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if ((off = find_unused_pages (len)) == (DWORD)-1)
return 0L;
if (wincap.virtual_protect_works_on_shared_pages ()
&& !VirtualProtect (base_address_ + off * getpagesize (),
len * getpagesize (), prot, &old_prot))
{
__seterrno ();
return (_off64_t)-1;
}
while (len-- > 0)
MAP_SET (off + len);
return off * getpagesize ();
}
bool
mmap_record::map_pages (caddr_t addr, DWORD len)
{
debug_printf ("map_pages (addr=%x, len=%u)", addr, len);
DWORD prot, old_prot;
DWORD off = addr - base_address_;
off /= getpagesize ();
len = PAGE_CNT (len);
/* First check if the area is unused right now. */
for (DWORD l = 0; l < len; ++l)
if (MAP_ISSET (off + l))
{
2005-05-02 05:50:11 +02:00
set_errno (EINVAL);
return false;
}
switch (access_mode_)
{
case FILE_MAP_WRITE:
prot = PAGE_READWRITE;
break;
case FILE_MAP_READ:
prot = PAGE_READONLY;
break;
default:
prot = PAGE_WRITECOPY;
break;
}
if (wincap.virtual_protect_works_on_shared_pages ()
&& !VirtualProtect (base_address_ + off * getpagesize (),
len * getpagesize (), prot, &old_prot))
{
__seterrno ();
return false;
}
for (; len-- > 0; ++off)
MAP_SET (off);
return true;
}
bool
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record::unmap_pages (caddr_t addr, DWORD len)
{
DWORD old_prot;
DWORD off = addr - base_address_;
off /= getpagesize ();
len = PAGE_CNT (len);
if (wincap.virtual_protect_works_on_shared_pages ()
&& !VirtualProtect (base_address_ + off * getpagesize (),
len * getpagesize (), PAGE_NOACCESS, &old_prot))
syscall_printf ("-1 = unmap_pages (), %E");
for (; len-- > 0; ++off)
MAP_CLR (off);
/* Return TRUE if all pages are free'd which may result in unmapping
the whole chunk. */
for (len = MAPSIZE (PAGE_CNT (size_to_map_)); len > 0; )
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (page_map_[--len])
return false;
return true;
}
void
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record::fixup_page_map ()
{
if (!wincap.virtual_protect_works_on_shared_pages ())
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)
VirtualProtect (base_address_ + (off - 1) * getpagesize (), getpagesize (),
MAP_ISSET (off - 1) ? prot : PAGE_NOACCESS, &old_prot);
}
int
mmap_record::access (caddr_t address)
{
if (address < base_address_ || address >= base_address_ + size_to_map_)
return 0;
DWORD off = (address - base_address_) / getpagesize ();
return MAP_ISSET (off);
}
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. */
* 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 02:37:18 +02:00
return build_fh_dev (get_device ());
}
void
mmap_record::free_fh (fhandler_base *fh)
{
if (get_fd () != -1)
cfree (fh);
}
mmap_record *
list::add_record (mmap_record r, _off64_t off, DWORD len)
2000-02-17 20:38:33 +01:00
{
if (nrecs == maxrecs)
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record *new_recs;
if (maxrecs == 0)
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
new_recs = (mmap_record *)
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
cmalloc (HEAP_MMAP, 5 * sizeof (mmap_record));
else
new_recs = (mmap_record *)
crealloc (recs, (maxrecs + 5) * sizeof (mmap_record));
if (!new_recs)
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
return NULL;
2000-02-17 20:38:33 +01:00
maxrecs += 5;
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
recs = new_recs;
2000-02-17 20:38:33 +01:00
}
recs[nrecs] = r;
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (!recs[nrecs].alloc_page_map (off, len))
return NULL;
return recs + nrecs++;
}
/* Used in mmap() */
mmap_record *
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list::search_record (_off64_t off, DWORD len)
{
if (fd == -1 && !off)
{
len = PAGE_CNT (len);
for (int i = 0; i < nrecs; ++i)
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (recs[i].find_unused_pages (len) != (DWORD)-1)
return recs + i;
}
else
{
for (int i = 0; i < nrecs; ++i)
if (off >= recs[i].get_offset ()
&& off + len <= recs[i].get_offset ()
+ (PAGE_CNT (recs[i].get_size ()) * getpagesize ()))
return recs + i;
}
return NULL;
}
/* Used in munmap() */
* cygwin.din (fstat64): New symbol. (ftruncate64): Ditto. (lseek64): Ditto. (lstat64): Ditto. (mmap64): Ditto. (seekdir64): Ditto. (stat64): Ditto. (telldir64): Ditto. (truncate64): Ditto. * dir.cc (telldir64): New function. (telldir): Call telldir64(). (seekdir64): New function. (seekdir): Call seekdir64(). * fhandler.h: Redefine all methods using __off32_t to use __off64_t. * fhandler.cc: Use __off64_t and struct __stat64 throughout. * fhandler_clipboard.cc: Ditto. * fhandler_disk_file.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_floppy.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_socket.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_zero.cc: Ditto. * pipe.cc: Ditto. * glob.c: Ditto, call lstat64 and stat64 in Cygwin. * mmap.cc: Use __off64_t throughout. (mmap64): New function. * sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64. * syscalls.cc (lseek64): New function. (stat64_to_stat32): Ditto. (fstat64): Ditto. (stat64): Ditto. (lstat64): Ditto. (ftruncate64): Ditto. (truncate64): Ditto. (_fstat): Call fstat64. (_stat): Call stat64. (cygwin_lstat): Rename to avoid declaration problem. Call lstat64. (stat_worker): Use struct __stat64. (access): Ditto. (ftruncate): Call ftruncate64. (truncate): Call truncate64. * wincap.cc: Set flag has_64bit_file_access appropriately. * wincap.h: Add flag has_64bit_file_access. * winsup.h (ILLEGAL_SEEK): Define as __off64_t. (stat_dev): Declare using struct __stat64. (stat_worker): Ditto. * include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin. (struct __stat64): Ditto. (struct stat): Revert definition with explicitly sized datatypes. Eliminate sized field names. * include/cygwin/types.h (blksize_t): New type. (__blkcnt32_t): Ditto. (__blkcnt64_t): Ditto. (blkcnt_t): Ditto.
2002-02-25 18:47:51 +01:00
long
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list::search_record (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len,
long start)
{
caddr_t low, high;
for (long i = start + 1; i < nrecs; ++i)
{
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;
}
}
* cygwin.din (fstat64): New symbol. (ftruncate64): Ditto. (lseek64): Ditto. (lstat64): Ditto. (mmap64): Ditto. (seekdir64): Ditto. (stat64): Ditto. (telldir64): Ditto. (truncate64): Ditto. * dir.cc (telldir64): New function. (telldir): Call telldir64(). (seekdir64): New function. (seekdir): Call seekdir64(). * fhandler.h: Redefine all methods using __off32_t to use __off64_t. * fhandler.cc: Use __off64_t and struct __stat64 throughout. * fhandler_clipboard.cc: Ditto. * fhandler_disk_file.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_floppy.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_socket.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_zero.cc: Ditto. * pipe.cc: Ditto. * glob.c: Ditto, call lstat64 and stat64 in Cygwin. * mmap.cc: Use __off64_t throughout. (mmap64): New function. * sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64. * syscalls.cc (lseek64): New function. (stat64_to_stat32): Ditto. (fstat64): Ditto. (stat64): Ditto. (lstat64): Ditto. (ftruncate64): Ditto. (truncate64): Ditto. (_fstat): Call fstat64. (_stat): Call stat64. (cygwin_lstat): Rename to avoid declaration problem. Call lstat64. (stat_worker): Use struct __stat64. (access): Ditto. (ftruncate): Call ftruncate64. (truncate): Call truncate64. * wincap.cc: Set flag has_64bit_file_access appropriately. * wincap.h: Add flag has_64bit_file_access. * winsup.h (ILLEGAL_SEEK): Define as __off64_t. (stat_dev): Declare using struct __stat64. (stat_worker): Ditto. * include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin. (struct __stat64): Ditto. (struct stat): Revert definition with explicitly sized datatypes. Eliminate sized field names. * include/cygwin/types.h (blksize_t): New type. (__blkcnt32_t): Ditto. (__blkcnt64_t): Ditto. (blkcnt_t): Ditto.
2002-02-25 18:47:51 +01:00
return -1;
2000-02-17 20:38:33 +01:00
}
void
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list::set (int nfd)
2000-02-17 20:38:33 +01:00
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if ((fd = nfd) != -1)
hash = cygheap->fdtab[fd]->get_namehash ();
nrecs = maxrecs = 0;
recs = NULL;
2000-02-17 20:38:33 +01:00
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
bool
list::del_record (int i)
2000-02-17 20:38:33 +01:00
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (i < nrecs)
{
recs[i].free_page_map ();
for (; i < nrecs - 1; i++)
recs[i] = recs[i + 1];
nrecs--;
}
/* Return true if the list is empty which allows the caller to remove
this list from the list array. */
return !nrecs;
2000-02-17 20:38:33 +01:00
}
list *
map::get_list_by_fd (int fd)
{
int i;
for (i=0; i<nlists; i++)
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
/* The fd isn't sufficient since it could already be the fd of another
file. So we use the name hash value to identify the file unless
it's an anonymous mapping in which case the fd (-1) is sufficient. */
if ((fd == -1 && lists[i].get_fd () == -1)
|| (fd != -1
&& lists[i].get_hash () == cygheap->fdtab[fd]->get_namehash ()))
return lists + i;
2000-02-17 20:38:33 +01:00
return 0;
}
list *
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
map::add_list (int fd)
2000-02-17 20:38:33 +01:00
{
if (nlists == maxlists)
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list *new_lists;
if (maxlists == 0)
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
new_lists = (list *) cmalloc (HEAP_MMAP, 5 * sizeof (list));
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
else
new_lists = (list *) crealloc (lists, (maxlists + 5) * sizeof (list));
if (!new_lists)
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
return NULL;
2000-02-17 20:38:33 +01:00
maxlists += 5;
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
lists = new_lists;
2000-02-17 20:38:33 +01:00
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
lists[nlists].set (fd);
return lists + nlists++;
2000-02-17 20:38:33 +01:00
}
void
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
map::del_list (int i)
2000-02-17 20:38:33 +01:00
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (i < nlists)
{
lists[i].free_recs ();
for (; i < nlists - 1; i++)
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
lists[i] = lists[i + 1];
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
nlists--;
}
2000-02-17 20:38:33 +01:00
}
extern "C" void *
mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
2000-02-17 20:38:33 +01:00
{
syscall_printf ("addr %x, len %u, prot %x, flags %x, fd %d, off %D",
2000-02-17 20:38:33 +01:00
addr, len, prot, flags, fd, off);
DWORD granularity = getshmlba ();
/* Error conditions according to SUSv2 */
if (off % getpagesize ()
|| (!(flags & MAP_SHARED) && !(flags & MAP_PRIVATE))
|| ((flags & MAP_SHARED) && (flags & MAP_PRIVATE))
|| ((flags & MAP_FIXED) && ((DWORD)addr % getpagesize ()))
|| !len)
{
set_errno (EINVAL);
syscall_printf ("-1 = mmap(): EINVAL");
return MAP_FAILED;
}
SetResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
2000-02-17 20:38:33 +01:00
if (mmapped_areas == NULL)
2000-02-17 20:38:33 +01:00
{
/* First mmap call, create STL map */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmapped_areas = (map *) ccalloc (HEAP_MMAP, 1, sizeof (map));
if (mmapped_areas == NULL)
2000-02-17 20:38:33 +01:00
{
set_errno (ENOMEM);
syscall_printf ("-1 = mmap(): ENOMEM");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED;
}
}
if (flags & MAP_ANONYMOUS)
fd = -1;
fhandler_base *fh = NULL;
2000-02-17 20:38:33 +01:00
/* Get fhandler and convert /dev/zero mapping to MAP_ANONYMOUS mapping. */
if (fd != -1)
2000-02-17 20:38:33 +01:00
{
/* Ensure that fd is open */
cygheap_fdget cfd (fd);
if (cfd < 0)
2000-02-17 20:38:33 +01:00
{
syscall_printf ("-1 = mmap(): EBADF");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED;
2000-02-17 20:38:33 +01:00
}
fh = cfd;
if (fh->get_device () == FH_ZERO)
2005-05-02 05:50:11 +02:00
{
/* mmap /dev/zero is like MAP_ANONYMOUS. */
fd = -1;
flags |= MAP_ANONYMOUS;
}
}
if (fd == -1)
{
fh_paging_file.set_io_handle (INVALID_HANDLE_VALUE);
fh = &fh_paging_file;
}
/* 9x only: If MAP_FIXED is requested on a non-granularity boundary,
change request so that this looks like a request with offset
addr % granularity. */
if (wincap.share_mmaps_only_by_name () && fd == -1 && (flags & MAP_FIXED)
&& ((DWORD)addr % granularity) && !off)
off = (DWORD)addr % granularity;
/* Map always in multipliers of `granularity'-sized chunks.
Not necessary for anonymous maps on NT. */
_off64_t gran_off = off;
DWORD gran_len = len;
if (wincap.share_mmaps_only_by_name () || fd != -1)
{
gran_off = off & ~(granularity - 1);
gran_len = howmany (off + len, granularity) * granularity - gran_off;
}
/* File mappings needs some extra care. */
if (fd != -1 && fh->get_device () == FH_FS)
{
DWORD high;
DWORD low = GetFileSize (fh->get_handle (), &high);
_off64_t fsiz = ((_off64_t)high << 32) + low;
/* Don't allow mappings beginning beyond EOF since Windows can't
handle that POSIX like, unless MAP_AUTOGROW flag is set, which
mimics Windows behaviour. FIXME: Still looking for a good idea
to allow that under POSIX rules. */
if (gran_off >= fsiz && !(flags & MAP_AUTOGROW))
{
set_errno (ENXIO);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
/* Don't map beyond EOF. Windows would change the file to the
2005-05-02 05:50:11 +02:00
new length otherwise, in contrast to POSIX. Allow mapping
beyon EOF if MAP_AUTOGROW flag is set. */
fsiz -= gran_off;
if (gran_len > fsiz)
2005-05-02 05:50:11 +02:00
{
if ((flags & MAP_AUTOGROW) && (off - gran_off) + len > fsiz)
{
/* Check if file has been opened for writing. */
if (!(fh->get_access () & GENERIC_WRITE))
{
set_errno (EINVAL);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
gran_len = (off - gran_off) + len;
}
else
gran_len = fsiz;
}
/* If the requested len is <= file size, drop the MAP_AUTOGROW flag.
2005-05-02 05:50:11 +02:00
This simplifes fhandler::mmap's job. */
if ((flags & MAP_AUTOGROW) && gran_len <= fsiz)
2005-05-02 05:50:11 +02:00
flags &= ~MAP_AUTOGROW;
}
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
sharing file mappings only works reliable using named
file mapping on 9x.
*/
if ((flags & MAP_PRIVATE)
&& (wincap.has_working_copy_on_write () || fd != -1))
access = FILE_MAP_COPY;
list *map_list = mmapped_areas->get_list_by_fd (fd);
/* A bit of memory munging on 9x. */
if (map_list && fd == -1 && wincap.share_mmaps_only_by_name ())
{
/* First check if this mapping matches into the chunk of another
already performed mapping. Only valid for MAP_ANON in a special
case of MAP_PRIVATE. */
if (off == 0 && !(flags & MAP_FIXED))
{
mmap_record *rec;
if ((rec = map_list->search_record (off, len)) != NULL
&& rec->get_access () == access)
{
if ((off = rec->map_pages (off, len)) == (_off64_t)-1)
{
syscall_printf ("-1 = mmap()");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK|WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
caddr_t ret = rec->get_address () + off;
syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return ret;
}
}
if ((flags & MAP_FIXED))
{
caddr_t u_addr;
DWORD u_len;
long record_idx = -1;
if ((record_idx = map_list->search_record ((caddr_t)addr, len,
2005-05-02 05:50:11 +02:00
u_addr, u_len,
record_idx)) >= 0)
{
mmap_record *rec = map_list->get_record (record_idx);
if (u_addr > (caddr_t)addr || u_addr + len < (caddr_t)addr + len
|| rec->get_access () != access)
{
/* Partial match only, or access mode doesn't match. */
/* FIXME: Handle partial mappings gracefully if adjacent
memory is available. */
set_errno (EINVAL);
syscall_printf ("-1 = mmap()");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
if (!rec->map_pages ((caddr_t)addr, len))
{
syscall_printf ("-1 = mmap()");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
caddr_t ret = (caddr_t)addr;
syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return ret;
}
}
}
caddr_t base = (caddr_t)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-17 20:38:33 +01:00
if (h == INVALID_HANDLE_VALUE)
2000-02-17 20:38:33 +01:00
{
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED;
2000-02-17 20:38:33 +01:00
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
/* At this point we should have a successfully mmapped area.
Now it's time for bookkeeping stuff. */
if (fd == -1)
gran_len = PAGE_CNT (gran_len) * getpagesize ();
mmap_record mmap_rec (fd, h, access, flags, gran_off, gran_len, base);
2000-02-17 20:38:33 +01:00
/* Get list of mmapped areas for this fd, create a new one if
one does not exist yet.
*/
if (!map_list)
2000-02-17 20:38:33 +01:00
{
/* Create a new one */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
map_list = mmapped_areas->add_list (fd);
if (!map_list)
{
fh->munmap (h, base, gran_len);
set_errno (ENOMEM);
syscall_printf ("-1 = mmap(): ENOMEM");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED;
}
2000-02-17 20:38:33 +01:00
}
/* Insert into the list */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record *rec = map_list->add_record (mmap_rec, off,
len > gran_len ? gran_len : len);
if (!rec)
{
fh->munmap (h, base, gran_len);
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 - gran_off);
syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return ret;
2000-02-17 20:38:33 +01:00
}
extern "C" void *
mmap (void *addr, size_t len, int prot, int flags, int fd, _off_t off)
* cygwin.din (fstat64): New symbol. (ftruncate64): Ditto. (lseek64): Ditto. (lstat64): Ditto. (mmap64): Ditto. (seekdir64): Ditto. (stat64): Ditto. (telldir64): Ditto. (truncate64): Ditto. * dir.cc (telldir64): New function. (telldir): Call telldir64(). (seekdir64): New function. (seekdir): Call seekdir64(). * fhandler.h: Redefine all methods using __off32_t to use __off64_t. * fhandler.cc: Use __off64_t and struct __stat64 throughout. * fhandler_clipboard.cc: Ditto. * fhandler_disk_file.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_floppy.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_socket.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_zero.cc: Ditto. * pipe.cc: Ditto. * glob.c: Ditto, call lstat64 and stat64 in Cygwin. * mmap.cc: Use __off64_t throughout. (mmap64): New function. * sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64. * syscalls.cc (lseek64): New function. (stat64_to_stat32): Ditto. (fstat64): Ditto. (stat64): Ditto. (lstat64): Ditto. (ftruncate64): Ditto. (truncate64): Ditto. (_fstat): Call fstat64. (_stat): Call stat64. (cygwin_lstat): Rename to avoid declaration problem. Call lstat64. (stat_worker): Use struct __stat64. (access): Ditto. (ftruncate): Call ftruncate64. (truncate): Call truncate64. * wincap.cc: Set flag has_64bit_file_access appropriately. * wincap.h: Add flag has_64bit_file_access. * winsup.h (ILLEGAL_SEEK): Define as __off64_t. (stat_dev): Declare using struct __stat64. (stat_worker): Ditto. * include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin. (struct __stat64): Ditto. (struct stat): Revert definition with explicitly sized datatypes. Eliminate sized field names. * include/cygwin/types.h (blksize_t): New type. (__blkcnt32_t): Ditto. (__blkcnt64_t): Ditto. (blkcnt_t): Ditto.
2002-02-25 18:47:51 +01:00
{
return mmap64 (addr, len, prot, flags, fd, (_off64_t)off);
* cygwin.din (fstat64): New symbol. (ftruncate64): Ditto. (lseek64): Ditto. (lstat64): Ditto. (mmap64): Ditto. (seekdir64): Ditto. (stat64): Ditto. (telldir64): Ditto. (truncate64): Ditto. * dir.cc (telldir64): New function. (telldir): Call telldir64(). (seekdir64): New function. (seekdir): Call seekdir64(). * fhandler.h: Redefine all methods using __off32_t to use __off64_t. * fhandler.cc: Use __off64_t and struct __stat64 throughout. * fhandler_clipboard.cc: Ditto. * fhandler_disk_file.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_floppy.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_socket.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_zero.cc: Ditto. * pipe.cc: Ditto. * glob.c: Ditto, call lstat64 and stat64 in Cygwin. * mmap.cc: Use __off64_t throughout. (mmap64): New function. * sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64. * syscalls.cc (lseek64): New function. (stat64_to_stat32): Ditto. (fstat64): Ditto. (stat64): Ditto. (lstat64): Ditto. (ftruncate64): Ditto. (truncate64): Ditto. (_fstat): Call fstat64. (_stat): Call stat64. (cygwin_lstat): Rename to avoid declaration problem. Call lstat64. (stat_worker): Use struct __stat64. (access): Ditto. (ftruncate): Call ftruncate64. (truncate): Call truncate64. * wincap.cc: Set flag has_64bit_file_access appropriately. * wincap.h: Add flag has_64bit_file_access. * winsup.h (ILLEGAL_SEEK): Define as __off64_t. (stat_dev): Declare using struct __stat64. (stat_worker): Ditto. * include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin. (struct __stat64): Ditto. (struct stat): Revert definition with explicitly sized datatypes. Eliminate sized field names. * include/cygwin/types.h (blksize_t): New type. (__blkcnt32_t): Ditto. (__blkcnt64_t): Ditto. (blkcnt_t): Ditto.
2002-02-25 18:47:51 +01:00
}
/* munmap () removes all mmapped pages between addr and addr+len. */
2000-02-17 20:38:33 +01:00
extern "C" int
munmap (void *addr, size_t len)
2000-02-17 20:38:33 +01:00
{
syscall_printf ("munmap (addr %x, len %u)", addr, len);
2000-02-17 20:38:33 +01:00
/* Error conditions according to SUSv3 */
if (!addr || ((DWORD)addr % getpagesize ()) || !len
|| check_invalid_virtual_addr (addr, len))
{
set_errno (EINVAL);
syscall_printf ("-1 = munmap(): Invalid parameters");
return -1;
}
SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
if (mmapped_areas == NULL)
2000-02-17 20:38:33 +01:00
{
syscall_printf ("-1 = munmap(): mmapped_areas == NULL");
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
return 0;
2000-02-17 20:38:33 +01:00
}
/* Iterate through the map, unmap pages between addr and addr+len
in all maps. */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list *map_list;
for (int list_idx = 0;
(map_list = mmapped_areas->get_list (list_idx));
++list_idx)
2000-02-17 20:38:33 +01:00
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
long record_idx = -1;
caddr_t u_addr;
DWORD u_len;
while ((record_idx = map_list->search_record((caddr_t)addr, len, u_addr,
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
u_len, record_idx)) >= 0)
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
{
mmap_record *rec = map_list->get_record (record_idx);
if (rec->unmap_pages (u_addr, u_len))
2000-02-17 20:38:33 +01:00
{
/* The whole record has been unmapped, so we now actually
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
unmap it from the system in full length... */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
fhandler_base *fh = rec->alloc_fh ();
fh->munmap (rec->get_handle (),
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
rec->get_address (),
rec->get_size ());
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
rec->free_fh (fh);
/* ...and delete the record. */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
if (map_list->del_record (record_idx--))
{
/* Yay, the last record has been removed from the list,
we can remove the list now, too. */
mmapped_areas->del_list (list_idx--);
break;
2000-02-17 20:38:33 +01:00
}
}
}
}
2000-02-17 20:38:33 +01:00
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
syscall_printf ("0 = munmap(): %x", addr);
return 0;
2000-02-17 20:38:33 +01:00
}
/* Sync file with memory. Ignore flags for now. */
extern "C" int
msync (void *addr, size_t len, int flags)
2000-02-17 20:38:33 +01:00
{
syscall_printf ("addr %x, len %u, flags %x", addr, len, flags);
2000-02-17 20:38:33 +01: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;
}
SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
/* Check if a mmap'ed area was ever created */
if (mmapped_areas == NULL)
{
syscall_printf ("-1 = msync(): mmapped_areas == NULL");
set_errno (EINVAL);
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
return -1;
}
/* Iterate through the map, looking for the mmapped area.
Error if not found. */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list *map_list;
for (int list_idx = 0;
(map_list = mmapped_areas->get_list (list_idx));
++list_idx)
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record *rec;
for (int record_idx = 0;
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
(rec = map_list->get_record (record_idx));
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
++record_idx)
{
if (rec->access ((caddr_t)addr))
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
/* Check whole area given by len. */
for (DWORD i = getpagesize (); i < len; ++i)
if (!rec->access ((caddr_t)addr + i))
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
goto invalid_address_range;
fhandler_base *fh = rec->alloc_fh ();
int ret = fh->msync (rec->get_handle (), (caddr_t)addr, len,
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
flags);
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
rec->free_fh (fh);
if (ret)
syscall_printf ("%d = msync(), %E", ret);
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
else
syscall_printf ("0 = msync()");
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK,
"msync");
return 0;
}
}
}
invalid_address_range:
/* SUSv2: Return code if indicated memory was not mapped is ENOMEM. */
set_errno (ENOMEM);
syscall_printf ("-1 = msync(): ENOMEM");
ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
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;
}
/* 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 */
bool writecopy = false;
if (prot & PROT_WRITE)
{
MEMORY_BASIC_INFORMATION mbi;
if (VirtualQuery (addr, &mbi, sizeof mbi))
{
if (mbi.AllocationProtect == PAGE_WRITECOPY
|| mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY)
writecopy = true;
}
}
switch (prot)
{
case PROT_READ | PROT_WRITE | PROT_EXEC:
case PROT_WRITE | PROT_EXEC:
new_prot = writecopy ? PAGE_EXECUTE_WRITECOPY : PAGE_EXECUTE_READWRITE;
break;
case PROT_READ | PROT_WRITE:
case PROT_WRITE:
new_prot = writecopy ? PAGE_WRITECOPY : 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:
*
* `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,
int flags, _off64_t off)
{
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;
}
bool
fhandler_base::fixup_mmap_after_fork (HANDLE h, DWORD access, int flags,
_off64_t offset, DWORD size,
void *address)
{
set_errno (ENODEV);
return -1;
}
/* Implementation for disk files. */
HANDLE
fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
int flags, _off64_t off)
{
DWORD protect;
switch (access)
{
case FILE_MAP_WRITE:
2003-03-09 21:31:07 +01:00
protect = PAGE_READWRITE;
break;
case FILE_MAP_READ:
2003-03-09 21:31:07 +01:00
protect = PAGE_READONLY;
break;
default:
protect = PAGE_WRITECOPY;
break;
}
HANDLE h;
DWORD high, low;
/* 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... */
if (wincap.share_mmaps_only_by_name ()
&& get_handle () != INVALID_HANDLE_VALUE
&& !(access & FILE_MAP_COPY))
{
/* Grrr, the whole stuff is just needed to try to get a reliable
mapping of the same file. Even that uprising isn't bullet
proof but it does it's best... */
char namebuf[CYG_MAX_PATH];
cygwin_conv_to_full_posix_path (get_name (), namebuf);
for (int i = strlen (namebuf) - 1; i >= 0; --i)
namebuf[i] = cyg_tolower (namebuf [i]);
debug_printf ("named sharing");
if (!(h = OpenFileMapping (access, TRUE, namebuf)))
h = CreateFileMapping (get_handle (), &sec_none, protect, 0, 0,
namebuf);
}
else if (get_handle () == INVALID_HANDLE_VALUE)
{
/* Standard anonymous mapping needs non-zero len. */
h = CreateFileMapping (get_handle (), &sec_none, protect, 0, len, NULL);
}
else if (flags & MAP_AUTOGROW)
{
high = (off + len) >> 32;
low = (off + len) & UINT32_MAX;
/* Auto-grow in CreateFileMapping only works if the protection is
2005-05-02 05:50:11 +02:00
PAGE_READWRITE. So, first we call CreateFileMapping with
PAGE_READWRITE, then, if the requested protection is different, we
close the mapping and reopen it again with the correct protection,
*iff* auto-grow worked. */
h = CreateFileMapping (get_handle (), &sec_none, PAGE_READWRITE,
high, low, NULL);
if (h && protect != PAGE_READWRITE)
2005-05-02 05:50:11 +02:00
{
CloseHandle (h);
h = CreateFileMapping (get_handle (), &sec_none, protect,
high, low, NULL);
}
}
else
{
/* Zero len creates mapping for whole file. */
h = CreateFileMapping (get_handle (), &sec_none, protect, 0, 0, NULL);
}
if (!h)
{
__seterrno ();
syscall_printf ("-1 = mmap(): CreateFileMapping failed with %E");
return INVALID_HANDLE_VALUE;
}
high = off >> 32;
low = off & UINT32_MAX;
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. */
if (!wincap.share_mmaps_only_by_name ()
&& get_handle () == INVALID_HANDLE_VALUE)
{
PHYSICAL_ADDRESS phys;
phys.QuadPart = (ULONGLONG) off;
ULONG ulen = len;
base = *addr ?: (void *) mmapped_areas->get_next_anon_addr ();
2005-05-02 05:50:11 +02:00
NTSTATUS ret = NtMapViewOfSection (h, INVALID_HANDLE_VALUE, &base, 0L,
ulen, &phys, &ulen, ViewShare,
base ? AT_ROUND_TO_PAGE : 0, protect);
if (ret != STATUS_SUCCESS)
2005-05-02 05:50:11 +02:00
{
__seterrno_from_nt_status (ret);
base = NULL;
}
else
mmapped_areas->set_next_anon_addr ((caddr_t) base + len);
}
else if (*addr)
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:%u, addr:%x)", base, h, access, off, len, *addr);
if (!base || ((flags & MAP_FIXED) && base != *addr))
{
if (!base)
{
__seterrno ();
syscall_printf ("-1 = mmap(): MapViewOfFileEx failed with %E");
}
else
{
set_errno (EINVAL);
syscall_printf ("-1 = mmap(): address shift with MAP_FIXED given");
}
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-17 20:38:33 +01:00
if (FlushViewOfFile (addr, len) == 0)
{
__seterrno ();
return -1;
}
return 0;
}
bool
fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, DWORD access, int flags,
_off64_t offset, DWORD size,
void *address)
{
/* Re-create the MapViewOfFileEx call */
void *base;
if (!wincap.share_mmaps_only_by_name () && (flags & MAP_ANONYMOUS))
{
PHYSICAL_ADDRESS phys;
phys.QuadPart = (ULONGLONG) offset;
ULONG ulen = size;
base = address;
DWORD protect;
switch (access)
{
case FILE_MAP_WRITE:
protect = PAGE_READWRITE;
break;
case FILE_MAP_READ:
protect = PAGE_READONLY;
break;
default:
protect = PAGE_WRITECOPY;
break;
}
2005-05-02 05:50:11 +02:00
NTSTATUS ret = NtMapViewOfSection (h, INVALID_HANDLE_VALUE, &base, 0L,
ulen, &phys, &ulen, ViewShare,
AT_ROUND_TO_PAGE, protect);
if (ret != STATUS_SUCCESS)
2005-05-02 05:50:11 +02:00
__seterrno_from_nt_status (ret);
}
else
base = MapViewOfFileEx (h, access, 0, offset, size, address);
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);
}
return base == address;
}
2000-02-17 20:38:33 +01: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
2000-02-17 20:38:33 +01: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
fixup_mmaps_after_fork (HANDLE parent)
2000-02-17 20:38:33 +01:00
{
debug_printf ("recreate_mmaps_after_fork, mmapped_areas %p", mmapped_areas);
2000-02-17 20:38:33 +01:00
/* Check if a mmapped area was ever created */
if (mmapped_areas == NULL)
2000-02-17 20:38:33 +01:00
return 0;
/* Iterate through the map */
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
list *map_list;
for (int list_idx = 0;
(map_list = mmapped_areas->get_list (list_idx));
++list_idx)
2000-02-17 20:38:33 +01:00
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
mmap_record *rec;
for (int record_idx = 0;
Eliminate use of sigframe and sigthread throughout. * Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
2003-11-28 21:55:59 +01:00
(rec = map_list->get_record (record_idx));
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
++record_idx)
2000-02-17 20:38:33 +01:00
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
debug_printf ("fd %d, h %x, access %x, offset %D, size %u, address %p",
rec->get_fd (), rec->get_handle (), rec->get_access (),
rec->get_offset (), rec->get_size (), rec->get_address ());
fhandler_base *fh = rec->alloc_fh ();
bool ret = fh->fixup_mmap_after_fork (rec->get_handle (),
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
rec->get_access (),
rec->get_flags (),
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
rec->get_offset (),
rec->get_size (),
rec->get_address ());
rec->free_fh (fh);
if (!ret)
return -1;
if (rec->get_access () == FILE_MAP_COPY)
{
for (char *address = rec->get_address ();
address < rec->get_address () + rec->get_size ();
address += getpagesize ())
if (rec->access (address)
&& !ReadProcessMemory (parent, address, address,
getpagesize (), NULL))
{
DWORD old_prot;
DWORD last_error = GetLastError ();
if (last_error != ERROR_PARTIAL_COPY
&& last_error != ERROR_NOACCESS
|| !wincap.virtual_protect_works_on_shared_pages ())
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
system_printf ("ReadProcessMemory failed for "
"MAP_PRIVATE address %p, %E",
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
{
BOOL ret;
DWORD dummy_prot;
ret = ReadProcessMemory (parent, address, address,
getpagesize (), NULL);
if (!VirtualProtectEx(parent,
address, getpagesize (),
old_prot, &dummy_prot))
system_printf ("WARNING: VirtualProtectEx to "
"return to previous state "
"in parent failed for "
"MAP_PRIVATE address %p, %E",
rec->get_address ());
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 ());
if (!ret)
{
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
system_printf ("ReadProcessMemory (2nd try) "
"failed for "
"MAP_PRIVATE address %p, %E",
rec->get_address ());
return -1;
}
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
}
}
* mmap.cc: Restructure. Add, remove and rewrite comments throughout for better readability. Change function names for better understanding. (MAP_SET): Accomodate name change from map_map_ to page_map_. (MAP_CLR): Ditto. (MAP_ISSET): Ditto. (mmap_record::page_map_): Rename from page_map_. (mmap_record::get_map): Remove. (mmap_record::alloc_page_map): Rename from alloc_map. Return bool indicating success of cygheap memory allocation. (mmap_record::free_page_map): Rename from free_map. (mmap_record::fixup_page_map): Rename from fixup_map. (mmap_record::find_unused_pages): Rename from find_empty. (mmap_record::map_pages): Rename from map_map. (mmap_record::unmap_pages): Rename from unmap_map. (class list): Make all class members private. (list::list): Remove. (list::~list): Remove. (list::get_fd): New attribute reader. (list::get_hash): Ditto. (list::get_record): Ditto. (list::add_record): Manage all allocation for mmap_records. Check for failed memory allocation and return NULL if so. (list::set): New function. (list::del_record): Rename from erase. Return true if last mmap_record has been deleted, false otherwise. Check for legal incoming index value. (list::erase): Remove erase/0. (list::search_record): Rename from match. (map::map): Remove. (map::~map): Remove. (map::add_list): Manage all allocation for lists. Check for failed memory allocation and return NULL if so. (map::get_list): New method. (map::del_list): Rename from erase. Check for legal incoming index value. (mmap64): Check for failed mmap_record memory allocation. Return with MAP_FAILED and errno set to ENOMEM if so. (munmap): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. Check if list can be deleted after last mmap_record in it has been deleted. (msync): Rearrange loop using new list and mmap_record accessor functions. Rename loop index variables for better understanding. (fixup_mmaps_after_fork): Ditto.
2003-09-04 12:27:51 +02:00
rec->fixup_page_map ();
}
}
2000-02-17 20:38:33 +01:00
debug_printf ("succeeded");
return 0;
}