Fix size returned by os_critsecsize() and construct type for D_CRITIAL_SECTION on Windows.

This commit is contained in:
kai
2012-09-08 11:49:37 +02:00
parent e333b76759
commit 4ae64dd2e7
3 changed files with 35 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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<LLType*> 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<LLType*> 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<LLType*> 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;