Changeset 14583


Ignore:
Timestamp:
Jan 18, 2011, 5:11:44 PM (14 years ago)
Author:
R. Matthew Emerson
Message:

New Windows-specific function reserve_tls_slots. Call it in main.

Location:
trunk/source/lisp-kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r14579 r14583  
    17101710    extern void init_winsock(void);
    17111711    extern void init_windows_io(void);
     1712    extern void reserve_tls_slots(void);
    17121713
    17131714    _fmode = O_BINARY;
     
    17171718    init_winsock();
    17181719    init_windows_io();
     1720    reserve_tls_slots();
    17191721    utf_16_argv = CommandLineToArgvW(GetCommandLineW(),&wide_argc);
    17201722  }
  • trunk/source/lisp-kernel/windows-calls.c

    r14012 r14583  
    10111011}
    10121012
     1013/*
     1014 * Reserve TLS slots 32 through 63 in the TEB for (part of) the TCR.
     1015 *
     1016 * On Windows 7 x64, #_TlsAlloc returns 23 in a fresh lisp.  On
     1017 * Windows XP, it returns 11.  With any luck, this will leave enough
     1018 * wiggle room for the C runtime or whatever to use a few more TLS
     1019 * slots, and still leave 32 through 63 free for us.
     1020 */
     1021void
     1022reserve_tls_slots()
     1023{
     1024  unsigned int first_available, n, i;
     1025
     1026  first_available = TlsAlloc();
     1027  if (first_available > 32) {
     1028    fprintf(dbgout, "Can't allocate required TLS indexes.\n");
     1029    fprintf(dbgout, "First available index value was %u\n", first_available);
     1030    exit(1);
     1031  }
     1032  TlsFree(first_available);
     1033
     1034  for (i = first_available; i < 32; i++) {
     1035    n = TlsAlloc();
     1036    if (n != i) {
     1037      fprintf(dbgout, "unexpected TLS index value: wanted %u, got %u\n", i, n);
     1038      exit(1);
     1039    }
     1040  }
     1041  for (i = 32; i < 64; i++) {
     1042    n = TlsAlloc();
     1043    if (n != i) {
     1044      fprintf(dbgout, "unexpected TLS index value: wanted %u, got %u\n", i, n);
     1045      exit(1);
     1046    }
     1047  }
     1048  for (i = first_available; i < 32; i++)
     1049    TlsFree(i);
     1050}
Note: See TracChangeset for help on using the changeset viewer.