Skip to content

Commit 6004928

Browse files
committed
Fixed bug #8850 : Firebird 3.0.13 Win32: KERNEL32.GetThreadId import breaks Windows XP (regression vs 3.0.12)
1 parent bd28d83 commit 6004928

5 files changed

Lines changed: 17 additions & 20 deletions

File tree

src/common/ThreadStart.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ ThreadId Thread::getId()
219219
#endif
220220
}
221221

222-
ThreadId Thread::getIdFromHandle(Handle threadHandle)
223-
{
224-
return threadHandle;
225-
}
226-
227222
bool Thread::isCurrent(InternalId iid)
228223
{
229224
return pthread_equal(iid, pthread_self());
@@ -373,11 +368,6 @@ ThreadId Thread::getId()
373368
return GetCurrentThreadId();
374369
}
375370

376-
ThreadId Thread::getIdFromHandle(Handle threadHandle)
377-
{
378-
return GetThreadId(threadHandle);
379-
}
380-
381371
bool Thread::isCurrent(InternalId iid)
382372
{
383373
return GetCurrentThreadId() == iid;
@@ -430,10 +420,6 @@ Thread::Handle Thread::getId()
430420
{
431421
}
432422

433-
Thread::Handle Thread::getIdFromHandle(Handle)
434-
{
435-
}
436-
437423
void Thread::sleep(unsigned milliseconds)
438424
{
439425
}

src/common/ThreadStart.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ class Thread
8282
static void waitForCompletion(Handle& handle);
8383
static void kill(Handle& handle);
8484

85+
// Returns TID of current OS thread
8586
static ThreadId getId();
86-
static ThreadId getIdFromHandle(Handle threadHandle);
87+
88+
// Returns internal ID of given thread instance
89+
InternalId getInternalId() const
90+
{
91+
return internalId;
92+
}
8793

8894
static void sleep(unsigned milliseconds);
8995
static void yield();

src/jrd/CryptoManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ namespace Jrd {
339339
flDown(false),
340340
run(false)
341341
{
342+
memset(&cryptThreadId, 0, sizeof(cryptThreadId));
343+
342344
stateLock = FB_NEW_RPT(getPool(), 0)
343345
Lock(tdbb, 0, LCK_crypt_status, this, blockingAstChangeCryptState);
344346
threadLock = FB_NEW_RPT(getPool(), 0) Lock(tdbb, 0, LCK_crypt);
@@ -995,7 +997,8 @@ namespace Jrd {
995997

996998
// ready to go
997999
guard.leave(); // release in advance to avoid races with cryptThread()
998-
Thread::start(cryptThreadStatic, (THREAD_ENTRY_PARAM) this, THREAD_medium, &cryptThreadHandle);
1000+
Thread& thread = Thread::start(cryptThreadStatic, (THREAD_ENTRY_PARAM) this, THREAD_medium, &cryptThreadHandle);
1001+
cryptThreadId = thread.getInternalId();
9991002
}
10001003
catch (const Firebird::Exception&)
10011004
{

src/jrd/CryptoManager.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,11 @@ class CryptoManager FB_FINAL : public Firebird::PermanentStorage, public BarSync
302302
ULONG getCurrentPage(thread_db* tdbb) const;
303303
UCHAR getCurrentState(thread_db* tdbb) const;
304304
const char* getKeyName() const;
305-
Thread::Handle getCryptThreadHandle() const
305+
306+
// Return true if crypt thread is running and it is the current thread.
307+
bool isCryptThreadCurrent() const
306308
{
307-
return cryptThreadHandle;
309+
return cryptThreadHandle && Thread::isCurrent(cryptThreadId);
308310
}
309311

310312
private:
@@ -393,6 +395,7 @@ class CryptoManager FB_FINAL : public Firebird::PermanentStorage, public BarSync
393395
Firebird::string hash;
394396
Firebird::RefPtr<DbInfo> dbInfo;
395397
Thread::Handle cryptThreadHandle;
398+
Thread::InternalId cryptThreadId;
396399
Firebird::IDbCryptPlugin* cryptPlugin;
397400
Factory* checkFactory;
398401
Database& dbb;

src/jrd/jrd.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6440,8 +6440,7 @@ static void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment)
64406440
// avoid races with special threads
64416441
XThreadEnsureUnlock threadGuard(dbb->dbb_thread_mutex, FB_FUNCTION);
64426442
XThreadEnsureUnlock* activeThreadGuard = &threadGuard;
6443-
if (dbb->dbb_crypto_manager
6444-
&& Thread::isCurrent(Thread::getIdFromHandle(dbb->dbb_crypto_manager->getCryptThreadHandle())))
6443+
if (dbb->dbb_crypto_manager && dbb->dbb_crypto_manager->isCryptThreadCurrent())
64456444
{
64466445
activeThreadGuard = &dummyGuard;
64476446
}

0 commit comments

Comments
 (0)