From de600ada776b78ff1b5bab5cc239a7a0127da756 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 27 Mar 2017 10:26:27 +0200 Subject: [PATCH] msvcrt: Add improper_lock class implementation. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/concrt140/concrt140.spec | 8 ++--- dlls/msvcr100/msvcr100.spec | 8 ++--- dlls/msvcr110/msvcr110.spec | 12 +++---- dlls/msvcr120/msvcr120.spec | 12 +++---- dlls/msvcr120_app/msvcr120_app.spec | 12 +++---- dlls/msvcrt/cpp.c | 52 +++++++++++++++++++++++++++++ dlls/msvcrt/lock.c | 6 ++-- dlls/msvcrt/msvcrt.h | 1 + 8 files changed, 82 insertions(+), 29 deletions(-) diff --git a/dlls/concrt140/concrt140.spec b/dlls/concrt140/concrt140.spec index 29efd72cf7a..c38c621a578 100644 --- a/dlls/concrt140/concrt140.spec +++ b/dlls/concrt140/concrt140.spec @@ -76,10 +76,10 @@ @ stub -arch=win64 ??0default_scheduler_exists@Concurrency@@QEAA@XZ @ thiscall -arch=win32 ??0event@Concurrency@@QAE@XZ(ptr) msvcr120.??0event@Concurrency@@QAE@XZ @ cdecl -arch=win64 ??0event@Concurrency@@QEAA@XZ(ptr) msvcr120.??0event@Concurrency@@QEAA@XZ -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z(ptr str) msvcr120.??0improper_lock@Concurrency@@QAE@PBD@Z +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z(ptr str) msvcr120.??0improper_lock@Concurrency@@QEAA@PEBD@Z +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ(ptr) msvcr120.??0improper_lock@Concurrency@@QAE@XZ +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ(ptr) msvcr120.??0improper_lock@Concurrency@@QEAA@XZ @ stub -arch=i386 ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z @ stub -arch=win64 ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z @ stub -arch=i386 ??0improper_scheduler_attach@Concurrency@@QAE@XZ diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index 4b54ab12c81..e9de64d6769 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -74,10 +74,10 @@ @ cdecl -arch=win64 ??0exception@std@@QEAA@AEBV01@@Z(ptr ptr) MSVCRT_exception_copy_ctor @ thiscall -arch=i386 ??0exception@std@@QAE@XZ(ptr) MSVCRT_exception_default_ctor @ cdecl -arch=win64 ??0exception@std@@QEAA@XZ(ptr) MSVCRT_exception_default_ctor -@ stub -arch=win32 ??0improper_lock@Concurrency@@QAE@PBD@Z -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z -@ stub -arch=win32 ??0improper_lock@Concurrency@@QAE@XZ -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z(ptr str) improper_lock_ctor_str +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z(ptr str) improper_lock_ctor_str +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ(ptr) improper_lock_ctor +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ(ptr) improper_lock_ctor @ stub -arch=win32 ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z @ stub -arch=win64 ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z @ stub -arch=win32 ??0improper_scheduler_attach@Concurrency@@QAE@XZ diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index 9526502174b..51dae1d3461 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -137,12 +137,12 @@ @ cdecl -arch=arm ??0exception@std@@QAA@XZ(ptr) MSVCRT_exception_default_ctor @ thiscall -arch=i386 ??0exception@std@@QAE@XZ(ptr) MSVCRT_exception_default_ctor @ cdecl -arch=win64 ??0exception@std@@QEAA@XZ(ptr) MSVCRT_exception_default_ctor -@ stub -arch=arm ??0improper_lock@Concurrency@@QAA@PBD@Z -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z -@ stub -arch=arm ??0improper_lock@Concurrency@@QAA@XZ -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ +@ cdecl -arch=arm ??0improper_lock@Concurrency@@QAA@PBD@Z(ptr str) improper_lock_ctor_str +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z(ptr str) improper_lock_ctor_str +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z(ptr str) improper_lock_ctor_str +@ cdecl -arch=arm ??0improper_lock@Concurrency@@QAA@XZ(ptr) improper_lock_ctor +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ(ptr) improper_lock_ctor +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ(ptr) improper_lock_ctor @ stub -arch=arm ??0improper_scheduler_attach@Concurrency@@QAA@PBD@Z @ stub -arch=i386 ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z @ stub -arch=win64 ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 4f9fbec7e44..6eb8d3e520a 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -134,12 +134,12 @@ @ cdecl -arch=arm ??0exception@std@@QAA@XZ(ptr) MSVCRT_exception_default_ctor @ thiscall -arch=i386 ??0exception@std@@QAE@XZ(ptr) MSVCRT_exception_default_ctor @ cdecl -arch=win64 ??0exception@std@@QEAA@XZ(ptr) MSVCRT_exception_default_ctor -@ stub -arch=arm ??0improper_lock@Concurrency@@QAA@PBD@Z -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z -@ stub -arch=arm ??0improper_lock@Concurrency@@QAA@XZ -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ +@ cdecl -arch=arm ??0improper_lock@Concurrency@@QAA@PBD@Z(ptr str) improper_lock_ctor_str +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z(ptr str) improper_lock_ctor_str +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z(ptr str) improper_lock_ctor_str +@ cdecl -arch=arm ??0improper_lock@Concurrency@@QAA@XZ(ptr) improper_lock_ctor +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ(ptr) improper_lock_ctor +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ(ptr) improper_lock_ctor @ stub -arch=arm ??0improper_scheduler_attach@Concurrency@@QAA@PBD@Z @ stub -arch=i386 ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z @ stub -arch=win64 ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z diff --git a/dlls/msvcr120_app/msvcr120_app.spec b/dlls/msvcr120_app/msvcr120_app.spec index 313d37cf850..25eab66513a 100644 --- a/dlls/msvcr120_app/msvcr120_app.spec +++ b/dlls/msvcr120_app/msvcr120_app.spec @@ -132,12 +132,12 @@ @ cdecl -arch=arm ??0exception@std@@QAA@XZ(ptr) msvcr120.??0exception@std@@QAA@XZ @ thiscall -arch=i386 ??0exception@std@@QAE@XZ(ptr) msvcr120.??0exception@std@@QAE@XZ @ cdecl -arch=win64 ??0exception@std@@QEAA@XZ(ptr) msvcr120.??0exception@std@@QEAA@XZ -@ stub -arch=arm ??0improper_lock@Concurrency@@QAA@PBD@Z -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z -@ stub -arch=arm ??0improper_lock@Concurrency@@QAA@XZ -@ stub -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ -@ stub -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ +@ cdecl -arch=arm ??0improper_lock@Concurrency@@QAA@PBD@Z(ptr str) msvcr120.??0improper_lock@Concurrency@@QAA@PBD@Z +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@PBD@Z(ptr str) msvcr120.??0improper_lock@Concurrency@@QAE@PBD@Z +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@PEBD@Z(ptr str) msvcr120.??0improper_lock@Concurrency@@QEAA@PEBD@Z +@ cdecl -arch=arm ??0improper_lock@Concurrency@@QAA@XZ(ptr) msvcr120.??0improper_lock@Concurrency@@QAA@XZ +@ thiscall -arch=i386 ??0improper_lock@Concurrency@@QAE@XZ(ptr) msvcr120.??0improper_lock@Concurrency@@QAE@XZ +@ cdecl -arch=win64 ??0improper_lock@Concurrency@@QEAA@XZ(ptr) msvcr120.??0improper_lock@Concurrency@@QEAA@XZ @ stub -arch=arm ??0improper_scheduler_attach@Concurrency@@QAA@PBD@Z @ stub -arch=i386 ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z @ stub -arch=win64 ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z diff --git a/dlls/msvcrt/cpp.c b/dlls/msvcrt/cpp.c index b5e21d9a7ee..70f5cb5a6c8 100644 --- a/dlls/msvcrt/cpp.c +++ b/dlls/msvcrt/cpp.c @@ -737,6 +737,44 @@ void __thiscall MSVCRT_scheduler_resource_allocation_error_dtor( TRACE("(%p)\n", this); MSVCRT_exception_dtor(&this->e); } + +typedef exception improper_lock; +extern const vtable_ptr MSVCRT_improper_lock_vtable; + +/* ??0improper_lock@Concurrency@@QAE@PBD@Z */ +/* ??0improper_lock@Concurrency@@QEAA@PEBD@Z */ +DEFINE_THISCALL_WRAPPER(improper_lock_ctor_str, 8) +improper_lock* __thiscall improper_lock_ctor_str(improper_lock *this, const char *str) +{ + TRACE("(%p %p)\n", this, str); + MSVCRT_exception_ctor(this, &str); + this->vtable = &MSVCRT_improper_lock_vtable; + return this; +} + +/* ??0improper_lock@Concurrency@@QAE@XZ */ +/* ??0improper_lock@Concurrency@@QEAA@XZ */ +DEFINE_THISCALL_WRAPPER(improper_lock_ctor, 4) +improper_lock* __thiscall improper_lock_ctor(improper_lock *this) +{ + return improper_lock_ctor_str(this, NULL); +} + +DEFINE_THISCALL_WRAPPER(MSVCRT_improper_lock_copy_ctor,8) +improper_lock * __thiscall MSVCRT_improper_lock_copy_ctor(improper_lock * _this, const improper_lock * rhs) +{ + TRACE("(%p %p)\n", _this, rhs); + MSVCRT_exception_copy_ctor(_this, rhs); + _this->vtable = &MSVCRT_improper_lock_vtable; + return _this; +} + +DEFINE_THISCALL_WRAPPER(MSVCRT_improper_lock_dtor,4) +void __thiscall MSVCRT_improper_lock_dtor(improper_lock * _this) +{ + TRACE("(%p)\n", _this); + MSVCRT_exception_dtor(_this); +} #endif #ifndef __GNUC__ @@ -769,6 +807,9 @@ __ASM_VTABLE(__non_rtti_object, __ASM_VTABLE(scheduler_resource_allocation_error, VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor) VTABLE_ADD_FUNC(MSVCRT_what_exception)); +__ASM_VTABLE(improper_lock, + VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor) + VTABLE_ADD_FUNC(MSVCRT_what_exception)); #endif #ifndef __GNUC__ @@ -792,6 +833,7 @@ DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exce #if _MSVCR_VER >= 100 DEFINE_RTTI_DATA1(scheduler_resource_allocation_error, 0, &exception_rtti_base_descriptor, ".?AVscheduler_resource_allocation_error@Concurrency@@") +DEFINE_RTTI_DATA1(improper_lock, 0, &exception_rtti_base_descriptor, ".?AVimproper_lock@Concurrency@@" ) #endif DEFINE_EXCEPTION_TYPE_INFO( exception, 0, NULL, NULL ) @@ -803,6 +845,7 @@ DEFINE_EXCEPTION_TYPE_INFO( bad_alloc, 1, &exception_cxx_type_info, NULL ) #endif #if _MSVCR_VER >= 100 DEFINE_EXCEPTION_TYPE_INFO(scheduler_resource_allocation_error, 1, &exception_cxx_type_info, NULL) +DEFINE_EXCEPTION_TYPE_INFO(improper_lock, 1, &exception_cxx_type_info, NULL) #endif void msvcrt_init_exception(void *base) @@ -819,6 +862,7 @@ void msvcrt_init_exception(void *base) init___non_rtti_object_rtti(base); #if _MSVCR_VER >= 100 init_scheduler_resource_allocation_error_rtti(base); + init_improper_lock_rtti(base); #endif init_exception_cxx(base); @@ -830,6 +874,7 @@ void msvcrt_init_exception(void *base) #endif #if _MSVCR_VER >= 100 init_scheduler_resource_allocation_error_cxx(base); + init_improper_lock_cxx(base); #endif #endif } @@ -850,6 +895,13 @@ void throw_scheduler_resource_allocation_error(const char *str, HRESULT hr) scheduler_resource_allocation_error_ctor_name(&e, str, hr); _CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type); } + +void throw_improper_lock(const char *str) +{ + improper_lock e; + improper_lock_ctor_str(&e, str); + _CxxThrowException(&e, &improper_lock_exception_type); +} #endif /****************************************************************** diff --git a/dlls/msvcrt/lock.c b/dlls/msvcrt/lock.c index edfefdbd986..c2efae1022f 100644 --- a/dlls/msvcrt/lock.c +++ b/dlls/msvcrt/lock.c @@ -1026,7 +1026,7 @@ void __thiscall reader_writer_lock_lock(reader_writer_lock *this) TRACE("(%p)\n", this); if (this->thread_id == GetCurrentThreadId()) - FIXME("throw improper_lock exception\n"); + throw_improper_lock("Already locked"); last = InterlockedExchangePointer((void**)&this->writer_tail, &q); if (last) { @@ -1057,7 +1057,7 @@ void __thiscall reader_writer_lock_lock_read(reader_writer_lock *this) TRACE("(%p)\n", this); if (this->thread_id == GetCurrentThreadId()) - FIXME("throw improper_lock exception\n"); + throw_improper_lock("Already locked as writer"); do { q.next = this->reader_head; @@ -1095,7 +1095,7 @@ MSVCRT_bool __thiscall reader_writer_lock_try_lock(reader_writer_lock *this) TRACE("(%p)\n", this); if (this->thread_id == GetCurrentThreadId()) - FIXME("throw improper_lock exception\n"); + return FALSE; if (InterlockedCompareExchangePointer((void**)&this->writer_tail, &q, NULL)) return FALSE; diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index dd957ef4e20..775ee0c789b 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -287,6 +287,7 @@ void throw_bad_alloc(const char*) DECLSPEC_HIDDEN; #endif #if _MSVCR_VER >= 100 void throw_scheduler_resource_allocation_error(const char*, HRESULT) DECLSPEC_HIDDEN; +void throw_improper_lock(const char*) DECLSPEC_HIDDEN; #endif void __cdecl _purecall(void);