From 4ae64dd2e7304db0bed7e61bb0786a7f718cf922 Mon Sep 17 00:00:00 2001 From: kai Date: Sat, 8 Sep 2012 11:49:37 +0200 Subject: [PATCH] Fix size returned by os_critsecsize() and construct type for D_CRITIAL_SECTION on Windows. --- dmd/statement.c | 6 +++--- dmd2/statement.c | 6 +++--- gen/tollvm.cpp | 33 +++++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/dmd/statement.c b/dmd/statement.c index 58673b45..0c7c9e4a 100644 --- a/dmd/statement.c +++ b/dmd/statement.c @@ -44,11 +44,11 @@ int os_critsecsize() { #if defined(_MSC_VER) - // TODO Check size - return 68; + // Return sizeof(RTL_CRITICAL_SECTION) + return global.params.is64bit ? 40 : 24; #else if (global.params.os == OSWindows) - return 68; + return global.params.is64bit ? 40 : 24; else if (global.params.os == OSFreeBSD) return sizeof(size_t); else diff --git a/dmd2/statement.c b/dmd2/statement.c index 87a4080c..6d94abee 100644 --- a/dmd2/statement.c +++ b/dmd2/statement.c @@ -41,11 +41,11 @@ int os_critsecsize() { #if defined(_MSC_VER) - // TODO Check size - return 68; + // Return sizeof(RTL_CRITICAL_SECTION) + return global.params.is64bit ? 40 : 24; #else if (global.params.os == OSWindows) - return 68; + return global.params.is64bit ? 40 : 24; else if (global.params.os == OSFreeBSD) return sizeof(size_t); else diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 64b2e55b..8282511b 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -917,12 +917,35 @@ LLStructType* DtoMutexType() if (gIR->mutexType) return gIR->mutexType; - // win32 + // The structures defined here must be the same as in druntime/src/rt/critical.c + + // Windows if (global.params.os == OSWindows) { - // CRITICAL_SECTION.sizeof == 68 - std::vector types(17, LLType::getInt32Ty(gIR->context())); - return LLStructType::get(gIR->context(), types); + llvm::Type *VoidPtrTy = llvm::Type::getInt8PtrTy(gIR->context()); + llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context()); + + // Build RTL_CRITICAL_SECTION; size is 24 (32bit) or 40 (64bit) + std::vector rtl_types; + rtl_types.push_back(VoidPtrTy); // Pointer to DebugInfo + rtl_types.push_back(Int32Ty); // LockCount + rtl_types.push_back(Int32Ty); // RecursionCount + rtl_types.push_back(VoidPtrTy); // Handle of OwningThread + rtl_types.push_back(VoidPtrTy); // Handle of LockSemaphore + rtl_types.push_back(VoidPtrTy); // SpinCount + LLStructType* rtl = LLStructType::create(gIR->context(), rtl_types, "RTL_CRITICAL_SECTION"); + + // Build D_CRITICAL_SECTION; size is 28 (32bit) or 48 (64bit) + LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); + std::vector types; + types.push_back(getPtrToType(mutex)); + types.push_back(rtl); + mutex->setBody(types); + + // Cache type + gIR->mutexType = mutex; + + return mutex; } // FreeBSD @@ -952,6 +975,8 @@ LLStructType* DtoMutexType() types.push_back(getPtrToType(mutex)); types.push_back(pmutex); mutex->setBody(types); + + // Cache type gIR->mutexType = mutex; return pmutex;