Skip to content

Commit

Permalink
Merge pull request #334 from astrangeguy/1.11
Browse files Browse the repository at this point in the history
make reserve_tls_slots() more lenient (fixes #311)
  • Loading branch information
xrme authored Sep 28, 2021
2 parents b712498 + 2d13cf7 commit e83ba43
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions lisp-kernel/windows-calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,30 +1028,31 @@ init_winsock()
void
reserve_tls_slots()
{
unsigned int first_available, n, i;
unsigned int last_slot, i, cnt_pad;
unsigned int pad_slots[30];

/* Since there is no way to reserve specific TLS indices, we reserve
* indices upto 30, hope to reserve 30 to 63 in one continuous block
* and then free those below 30.
*/
cnt_pad = 0;
do {
last_slot = TlsAlloc();
pad_slots[cnt_pad++] = last_slot;
} while (last_slot < 30 && cnt_pad < 30);

first_available = TlsAlloc();
if (first_available > 30) {
fprintf(dbgout, "Can't allocate required TLS indexes.\n");
fprintf(dbgout, "First available index value was %u\n", first_available);
if (last_slot != 30) {
fprintf(dbgout, "could not reserve TLS slots from 30 to 63: Slot %u already reserved\n", 30);
exit(1);
}
TlsFree(first_available);

for (i = first_available; i < 30; i++) {
n = TlsAlloc();
if (n != i) {
fprintf(dbgout, "unexpected TLS index value: wanted %u, got %u\n", i, n);
exit(1);
}
}
for (i = 30; i < 64; i++) {
n = TlsAlloc();
if (n != i) {
fprintf(dbgout, "unexpected TLS index value: wanted %u, got %u\n", i, n);
for (i = 31; i < 64; i++) {
last_slot = TlsAlloc();
if (last_slot != i) {
fprintf(dbgout, "could not reserve TLS slots from 30 to 63: Slot %u already reserved\n", i);
exit(1);
}
}
for (i = first_available; i < 30; i++)
TlsFree(i);
for (i = 0; i < cnt_pad; i++)
if (pad_slots[i] < 30)
TlsFree(pad_slots[i]);
}

0 comments on commit e83ba43

Please sign in to comment.