Drop old SetResourceLock stuff in favor of mutos.
* dcrt0.cc (_reslock): Remove. (__cygwin_user_data): Accommodate removal of resourcelocks member. (dll_crt0_0): Don't initialize resourcelocks. * exceptions.cc (_cygtls::signal_exit): Drop resourcelocks handling. * mmap.cc (mmap_guard): New muto. (LIST_LOCK): Define. (LIST_UNLOCK): Define. (mmap_list::search_record): Remove. (mmap_list::try_map): Include code for anonymous case from mmap_list::search_record. (mmap_is_attached_or_noreserve): Access bookkeeping lists in a thread safe way. (mmap64): Replace SetResourceLock/ReleaseResourceLock by LIST_LOCK/LIST_UNLOCK. Lock at the latest possible point. (munmap): Replace SetResourceLock/ReleaseResourceLock by LIST_LOCK/LIST_UNLOCK. (msync): Ditto. (mprotect): Ditto. * thread.cc (ResourceLocks::Lock): Remove. (SetResourceLock): Remove. (ReleaseResourceLock): Remove. (ResourceLocks::Init): Remove. (ResourceLocks::Delete): Remove. * thread.h (SetResourceLock): Drop declaration. (ReleaseResourceLock): Ditto. (class ResourceLocks): Drop definition. * include/sys/cygwin.h (class ResourceLocks): Drop forward declaration. (struct per_process): Replace resourcelocks with additional unused2 element. (per_process_overwrite): Accommodate above change.
This commit is contained in:
		
							parent
							
								
									230a3c86d1
								
							
						
					
					
						commit
						a1591d3be7
					
				|  | @ -1,3 +1,37 @@ | |||
| 2007-11-27  Corinna Vinschen  <corinna@vinschen.de> | ||||
| 
 | ||||
| 	Drop old SetResourceLock stuff in favor of mutos. | ||||
| 	* dcrt0.cc (_reslock): Remove. | ||||
| 	(__cygwin_user_data): Accommodate removal of resourcelocks member. | ||||
| 	(dll_crt0_0): Don't initialize resourcelocks. | ||||
| 	* exceptions.cc (_cygtls::signal_exit): Drop resourcelocks handling. | ||||
| 	* mmap.cc (mmap_guard): New muto. | ||||
| 	(LIST_LOCK): Define. | ||||
| 	(LIST_UNLOCK): Define. | ||||
| 	(mmap_list::search_record): Remove. | ||||
| 	(mmap_list::try_map): Include code for anonymous case from | ||||
| 	mmap_list::search_record. | ||||
| 	(mmap_is_attached_or_noreserve): Access bookkeeping lists in a thread | ||||
| 	safe way. | ||||
| 	(mmap64): Replace SetResourceLock/ReleaseResourceLock by | ||||
| 	LIST_LOCK/LIST_UNLOCK.  Lock at the latest possible point. | ||||
| 	(munmap): Replace SetResourceLock/ReleaseResourceLock by | ||||
| 	LIST_LOCK/LIST_UNLOCK. | ||||
| 	(msync): Ditto. | ||||
| 	(mprotect): Ditto. | ||||
| 	* thread.cc (ResourceLocks::Lock): Remove. | ||||
| 	(SetResourceLock): Remove. | ||||
| 	(ReleaseResourceLock): Remove. | ||||
| 	(ResourceLocks::Init): Remove. | ||||
| 	(ResourceLocks::Delete): Remove. | ||||
| 	* thread.h (SetResourceLock): Drop declaration. | ||||
| 	(ReleaseResourceLock): Ditto. | ||||
| 	(class ResourceLocks): Drop definition. | ||||
| 	* include/sys/cygwin.h (class ResourceLocks): Drop forward declaration. | ||||
| 	(struct per_process): Replace resourcelocks with additional unused2 | ||||
| 	element. | ||||
| 	(per_process_overwrite): Accommodate above change. | ||||
| 
 | ||||
| 2007-11-27  Corinna Vinschen  <corinna@vinschen.de> | ||||
| 
 | ||||
| 	* mmap.cc: Convert usage of dynamically growing cmalloced arrays to | ||||
|  |  | |||
|  | @ -80,7 +80,6 @@ bool NO_COPY cygwin_finished_initializing; | |||
|    measure to allow an orderly transfer to the new, correct sigmask method. */ | ||||
| unsigned NO_COPY int signal_shift_subtract = 1; | ||||
| 
 | ||||
| ResourceLocks _reslock NO_COPY; | ||||
| MTinterface _mtinterf; | ||||
| 
 | ||||
| bool NO_COPY _cygwin_testing; | ||||
|  | @ -113,8 +112,8 @@ extern "C" | |||
|    /* hmodule */ NULL, | ||||
|    /* api_major */ CYGWIN_VERSION_API_MAJOR, | ||||
|    /* api_minor */ CYGWIN_VERSION_API_MINOR, | ||||
|    /* unused2 */ {0, 0, 0, 0, 0}, | ||||
|    /* resourcelocks */ &_reslock, /* threadinterface */ &_mtinterf, | ||||
|    /* unused2 */ {0, 0, 0, 0, 0, 0}, | ||||
|    /* threadinterface */ &_mtinterf, | ||||
|    /* impure_ptr */ _GLOBAL_REENT, | ||||
|   }; | ||||
|   bool ignore_case_with_glob; | ||||
|  | @ -759,7 +758,6 @@ dll_crt0_0 () | |||
| 	} | ||||
|     } | ||||
| 
 | ||||
|   user_data->resourcelocks->Init (); | ||||
|   user_data->threadinterface->Init (); | ||||
| 
 | ||||
|   _cygtls::init (); | ||||
|  |  | |||
|  | @ -1286,9 +1286,6 @@ _cygtls::signal_exit (int rc) | |||
|      stupid. */ | ||||
|   SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); | ||||
| 
 | ||||
|   user_data->resourcelocks->Delete (); | ||||
|   user_data->resourcelocks->Init (); | ||||
| 
 | ||||
|   sigproc_printf ("about to call do_exit (%x)", rc); | ||||
|   SetEvent (signal_arrived); | ||||
|   do_exit (rc); | ||||
|  |  | |||
|  | @ -140,7 +140,6 @@ extern HANDLE cygwin_logon_user (const struct passwd *, const char *); | |||
| */ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| class ResourceLocks; | ||||
| class MTinterface; | ||||
| #endif | ||||
| 
 | ||||
|  | @ -198,18 +197,16 @@ struct per_process | |||
|   DWORD api_minor;		/*  linked with */ | ||||
|   /* For future expansion, so apps won't have to be relinked if we
 | ||||
|      add an item. */ | ||||
|   DWORD unused2[5]; | ||||
|   DWORD unused2[6]; | ||||
| 
 | ||||
| #if defined (__INSIDE_CYGWIN__) && defined (__cplusplus) | ||||
|   ResourceLocks *resourcelocks; | ||||
|   MTinterface *threadinterface; | ||||
| #else | ||||
|   void *resourcelocks; | ||||
|   void *threadinterface; | ||||
| #endif | ||||
|   struct _reent *impure_ptr; | ||||
| }; | ||||
| #define per_process_overwrite ((unsigned) &(((struct per_process *) NULL)->resourcelocks)) | ||||
| #define per_process_overwrite ((unsigned) &(((struct per_process *) NULL)->threadinterface)) | ||||
| 
 | ||||
| extern void cygwin_premain0 (int argc, char **argv, struct per_process *); | ||||
| extern void cygwin_premain1 (int argc, char **argv, struct per_process *); | ||||
|  |  | |||
|  | @ -51,6 +51,11 @@ details. */ | |||
| /* Used for anonymous mappings. */ | ||||
| static fhandler_dev_zero fh_anonymous; | ||||
| 
 | ||||
| /* Used for thread synchronization while accessing mmap bookkeeping lists. */ | ||||
| static NO_COPY muto mmap_guard; | ||||
| #define LIST_LOCK()    (mmap_guard.init ("mmap_guard")->acquire ()) | ||||
| #define LIST_UNLOCK()  (mmap_guard.release ()) | ||||
| 
 | ||||
| /* Small helpers to avoid having lots of flag bit tests in the code. */ | ||||
| static inline bool | ||||
| priv (int flags) | ||||
|  | @ -333,7 +338,6 @@ class mmap_list | |||
|     void set (int nfd, struct __stat64 *st); | ||||
|     mmap_record *add_record (mmap_record r); | ||||
|     bool del_record (mmap_record *rec); | ||||
|     mmap_record *search_record (_off64_t off, DWORD len); | ||||
|     caddr_t try_map (void *addr, size_t len, int flags, _off64_t off); | ||||
| }; | ||||
| 
 | ||||
|  | @ -552,31 +556,6 @@ mmap_list::add_record (mmap_record r) | |||
|   return rec; | ||||
| } | ||||
| 
 | ||||
| /* Used in mmap() */ | ||||
| mmap_record * | ||||
| mmap_list::search_record (_off64_t off, DWORD len) | ||||
| { | ||||
|   mmap_record *rec; | ||||
| 
 | ||||
|   if (anonymous () && !off) | ||||
|     { | ||||
|       len = PAGE_CNT (len); | ||||
|       LIST_FOREACH (rec, &recs, mr_next) | ||||
| 	if (rec->find_unused_pages (len) != (DWORD)-1) | ||||
| 	  return rec; | ||||
|     } | ||||
|   else | ||||
|     { | ||||
|       LIST_FOREACH (rec, &recs, mr_next) | ||||
| 	if (off >= rec->get_offset () | ||||
| 	    && off + len | ||||
| 	       <= rec->get_offset () | ||||
| 		  + (PAGE_CNT (rec->get_len ()) * getsystempagesize ())) | ||||
| 	  return rec; | ||||
|     } | ||||
|   return NULL; | ||||
| } | ||||
| 
 | ||||
| void | ||||
| mmap_list::set (int nfd, struct __stat64 *st) | ||||
| { | ||||
|  | @ -611,10 +590,13 @@ mmap_list::try_map (void *addr, size_t len, int flags, _off64_t off) | |||
|     { | ||||
|       /* If MAP_FIXED isn't given, check if this mapping matches into the
 | ||||
| 	 chunk of another already performed mapping. */ | ||||
|       if ((rec = search_record (off, len)) != NULL | ||||
| 	  && rec->compatible_flags (flags)) | ||||
|       DWORD plen = PAGE_CNT (len); | ||||
|       LIST_FOREACH (rec, &recs, mr_next) | ||||
| 	if (rec->find_unused_pages (plen) != (DWORD) -1) | ||||
| 	  break; | ||||
|       if (rec && rec->compatible_flags (flags)) | ||||
| 	{ | ||||
| 	  if ((off = rec->map_pages (off, len)) == (_off64_t)-1) | ||||
| 	  if ((off = rec->map_pages (off, len)) == (_off64_t) -1) | ||||
| 	    return (caddr_t) MAP_FAILED; | ||||
| 	  return (caddr_t) rec->get_address () + off; | ||||
| 	} | ||||
|  | @ -705,6 +687,9 @@ mmap_areas::del_list (mmap_list *ml) | |||
| mmap_region_status | ||||
| mmap_is_attached_or_noreserve (void *addr, size_t len) | ||||
| { | ||||
|   mmap_region_status ret = MMAP_NONE; | ||||
| 
 | ||||
|   LIST_LOCK (); | ||||
|   mmap_list *map_list = mmapped_areas.get_list_by_fd (-1, NULL); | ||||
| 
 | ||||
|   size_t pagesize = getpagesize (); | ||||
|  | @ -713,7 +698,7 @@ mmap_is_attached_or_noreserve (void *addr, size_t len) | |||
|   len = roundup2 (len, pagesize); | ||||
| 
 | ||||
|   if (map_list == NULL) | ||||
|     return MMAP_NONE; | ||||
|     goto out; | ||||
| 
 | ||||
|   mmap_record *rec; | ||||
|   caddr_t u_addr; | ||||
|  | @ -724,9 +709,12 @@ mmap_is_attached_or_noreserve (void *addr, size_t len) | |||
|       if (!rec->match (start_addr, len, u_addr, u_len)) | ||||
| 	continue; | ||||
|       if (rec->attached ()) | ||||
| 	return MMAP_RAISE_SIGBUS; | ||||
| 	{ | ||||
| 	  ret = MMAP_RAISE_SIGBUS; | ||||
| 	  break; | ||||
| 	} | ||||
|       if (!rec->noreserve ()) | ||||
| 	return MMAP_NONE; | ||||
| 	break; | ||||
| 
 | ||||
|       size_t commit_len = u_len - (start_addr - u_addr); | ||||
|       if (commit_len > len) | ||||
|  | @ -734,14 +722,22 @@ mmap_is_attached_or_noreserve (void *addr, size_t len) | |||
| 
 | ||||
|       if (!VirtualAlloc (start_addr, commit_len, MEM_COMMIT, | ||||
| 			 rec->gen_protect ())) | ||||
| 	return MMAP_RAISE_SIGBUS; | ||||
| 	{ | ||||
| 	  ret = MMAP_RAISE_SIGBUS; | ||||
| 	  break; | ||||
| 	} | ||||
| 
 | ||||
|       start_addr += commit_len; | ||||
|       len -= commit_len; | ||||
|       if (!len) | ||||
| 	return MMAP_NORESERVE_COMMITED; | ||||
| 	{ | ||||
| 	  ret = MMAP_NORESERVE_COMMITED; | ||||
| 	  break; | ||||
| 	} | ||||
|     } | ||||
|   return MMAP_NONE; | ||||
| out: | ||||
|   LIST_UNLOCK (); | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
| static caddr_t | ||||
|  | @ -788,8 +784,6 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off) | |||
|   fh_anonymous.set_io_handle (INVALID_HANDLE_VALUE); | ||||
|   fh_anonymous.set_access (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE); | ||||
| 
 | ||||
|   SetResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); | ||||
| 
 | ||||
|   /* EINVAL error conditions. */ | ||||
|   if (off % pagesize | ||||
|       || ((prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))) | ||||
|  | @ -939,6 +933,7 @@ go_ahead: | |||
|   if (noreserve (flags) && (!anonymous (flags) || !priv (flags))) | ||||
|     flags &= ~MAP_NORESERVE; | ||||
| 
 | ||||
|   LIST_LOCK (); | ||||
|   map_list = mmapped_areas.get_list_by_fd (fd, &st); | ||||
| 
 | ||||
|   /* Test if an existing anonymous mapping can be recycled. */ | ||||
|  | @ -946,11 +941,11 @@ go_ahead: | |||
|     { | ||||
|       caddr_t tried = map_list->try_map (addr, len, flags, off); | ||||
|       /* try_map returns NULL if no map matched, otherwise it returns
 | ||||
| 	 a valid address, of MAP_FAILED in case of a fatal error. */ | ||||
| 	 a valid address, or MAP_FAILED in case of a fatal error. */ | ||||
|       if (tried) | ||||
| 	{ | ||||
| 	  ret = tried; | ||||
| 	  goto out; | ||||
| 	  goto out_with_unlock; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
|  | @ -974,13 +969,13 @@ go_ahead: | |||
| 	  if (!newaddr) | ||||
| 	    { | ||||
| 	      __seterrno (); | ||||
| 	      goto out; | ||||
| 	      goto out_with_unlock; | ||||
| 	    } | ||||
| 	} | ||||
|       if (!VirtualFree (newaddr, 0, MEM_RELEASE)) | ||||
| 	{ | ||||
| 	  __seterrno (); | ||||
| 	  goto out; | ||||
| 	  goto out_with_unlock; | ||||
| 	} | ||||
|       addr = newaddr; | ||||
|     } | ||||
|  | @ -988,7 +983,7 @@ go_ahead: | |||
|   base = mmap_worker (map_list, fh, (caddr_t) addr, len, prot, flags, fd, off, | ||||
| 		      &st); | ||||
|   if (!base) | ||||
|     goto out; | ||||
|     goto out_with_unlock; | ||||
| 
 | ||||
|   if (orig_len) | ||||
|     { | ||||
|  | @ -1024,7 +1019,7 @@ go_ahead: | |||
| 		{ | ||||
| 		  fh->munmap (fh->get_handle (), base, len); | ||||
| 		  set_errno (ENOMEM); | ||||
| 		  goto out; | ||||
| 		  goto out_with_unlock; | ||||
| 		} | ||||
| 	      at_base += valid_page_len; | ||||
| 	    } | ||||
|  | @ -1042,9 +1037,10 @@ go_ahead: | |||
| 
 | ||||
|   ret = base; | ||||
| 
 | ||||
| out: | ||||
| out_with_unlock: | ||||
|   LIST_UNLOCK (); | ||||
| 
 | ||||
|   ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); | ||||
| out: | ||||
| 
 | ||||
|   if (fh_disk_file) | ||||
|     NtClose (fh_disk_file->get_handle ()); | ||||
|  | @ -1080,7 +1076,7 @@ munmap (void *addr, size_t len) | |||
|     } | ||||
|   len = roundup2 (len, pagesize); | ||||
| 
 | ||||
|   SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap"); | ||||
|   LIST_LOCK (); | ||||
| 
 | ||||
|   /* Iterate through the map, unmap pages between addr and addr+len
 | ||||
|      in all maps. */ | ||||
|  | @ -1117,7 +1113,7 @@ munmap (void *addr, size_t len) | |||
| 	} | ||||
|     } | ||||
| 
 | ||||
|   ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap"); | ||||
|   LIST_UNLOCK (); | ||||
|   syscall_printf ("0 = munmap(): %x", addr); | ||||
|   return 0; | ||||
| } | ||||
|  | @ -1132,7 +1128,7 @@ msync (void *addr, size_t len, int flags) | |||
| 
 | ||||
|   syscall_printf ("msync (addr: %p, len %u, flags %x)", addr, len, flags); | ||||
| 
 | ||||
|   SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync"); | ||||
|   LIST_LOCK (); | ||||
| 
 | ||||
|   if (((uintptr_t) addr % getpagesize ()) | ||||
|       || (flags & ~(MS_ASYNC | MS_SYNC | MS_INVALIDATE)) | ||||
|  | @ -1173,8 +1169,8 @@ msync (void *addr, size_t len, int flags) | |||
|   set_errno (ENOMEM); | ||||
| 
 | ||||
| out: | ||||
|   LIST_UNLOCK (); | ||||
|   syscall_printf ("%d = msync()", ret); | ||||
|   ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync"); | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
|  | @ -1199,7 +1195,7 @@ mprotect (void *addr, size_t len, int prot) | |||
|     } | ||||
|   len = roundup2 (len, pagesize); | ||||
| 
 | ||||
|   SetResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "mprotect"); | ||||
|   LIST_LOCK (); | ||||
| 
 | ||||
|   /* Iterate through the map, protect pages between addr and addr+len
 | ||||
|      in all maps. */ | ||||
|  | @ -1235,7 +1231,7 @@ mprotect (void *addr, size_t len, int prot) | |||
| 	} | ||||
|     } | ||||
| 
 | ||||
|   ReleaseResourceLock (LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "mprotect"); | ||||
|   LIST_UNLOCK (); | ||||
| 
 | ||||
|   if (!in_mapped) | ||||
|     { | ||||
|  |  | |||
|  | @ -286,43 +286,6 @@ semaphore::is_good_object (sem_t const * sem) | |||
|   return true; | ||||
| } | ||||
| 
 | ||||
| LPCRITICAL_SECTION | ||||
| ResourceLocks::Lock (int _resid) | ||||
| { | ||||
|   return &lock; | ||||
| } | ||||
| 
 | ||||
| void | ||||
| SetResourceLock (int _res_id, int _mode, const char *_function) | ||||
| { | ||||
|   EnterCriticalSection (user_data->resourcelocks->Lock (_res_id)); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| ReleaseResourceLock (int _res_id, int _mode, const char *_function) | ||||
| { | ||||
|   LeaveCriticalSection (user_data->resourcelocks->Lock (_res_id)); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| ResourceLocks::Init () | ||||
| { | ||||
|   InitializeCriticalSection (&lock); | ||||
|   inited = true; | ||||
|   thread_printf ("lock %p inited by %p , %d", &lock, user_data, myself->pid); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| ResourceLocks::Delete () | ||||
| { | ||||
|   if (inited) | ||||
|     { | ||||
|       thread_printf ("Close Resource Locks %p ", &lock); | ||||
|       DeleteCriticalSection (&lock); | ||||
|       inited = false; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void | ||||
| MTinterface::Init () | ||||
| { | ||||
|  |  | |||
|  | @ -35,13 +35,6 @@ enum cw_cancel_action | |||
|   cw_no_cancel | ||||
| }; | ||||
| 
 | ||||
| extern "C" | ||||
| { | ||||
| void SetResourceLock (int, int, const char *) __attribute__ ((regparm (3))); | ||||
| void ReleaseResourceLock (int, int, const char *) | ||||
|   __attribute__ ((regparm (3))); | ||||
| } | ||||
| 
 | ||||
| DWORD cancelable_wait (HANDLE, DWORD, const cw_cancel_action = cw_cancel_self, | ||||
| 		       const enum cw_sig_wait = cw_sig_nosig) | ||||
|   __attribute__ ((regparm (3))); | ||||
|  | @ -92,17 +85,6 @@ private: | |||
| class per_process; | ||||
| class pinfo; | ||||
| 
 | ||||
| class ResourceLocks | ||||
| { | ||||
| public: | ||||
|   LPCRITICAL_SECTION Lock (int); | ||||
|   void Init (); | ||||
|   void Delete (); | ||||
| private: | ||||
|   CRITICAL_SECTION lock; | ||||
|   bool inited; | ||||
| }; | ||||
| 
 | ||||
| #define PTHREAD_MAGIC 0xdf0df045 | ||||
| #define PTHREAD_MUTEX_MAGIC PTHREAD_MAGIC+1 | ||||
| #define PTHREAD_KEY_MAGIC PTHREAD_MAGIC+2 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue