title: GetThreadSelectorEntry throwing ERROR_NOT_SUPPORTED for x64 App
body: <p>I trying to write a very simple app to debug a Win32 64-bit app. My end goal is to get the TIB and PEB of the remote thread, but for some reason the way I did this on 32-bit app is not working for 64-bit ones (Aside from looking at Esp vs Rsp and checking SegFs vs SegGs). The code I'm trying to use is here:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;tlhelp32.h&gt;
  
  int main(int argc, char *argv[]){
    LDT_ENTRY             entry;
    DWORD                pid;
    HANDLE               hThread;
    HANDLE               hSnapshot;
    CONTEXT               context;
    context.ContextFlags = CONTEXT_CONTROL;
  
    if(argc &lt; 2){
      printf("Usage: %s PID\n", argv[0]);
      exit(1);
    }
  
    pid = atoi(argv[1]);
  
    THREADENTRY32 te32;
    te32.dwSize = sizeof(te32);
    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
    while(Thread32Next(hSnapshot, &amp;te32)){
      if(pid == te32.th32OwnerProcessID){
        hThread = OpenThread(THREAD_ALL_ACCESS, 0, te32.th32ThreadID);
        if(!hThread)
          exit(1);
  
        if(SuspendThread(hThread) == (DWORD) -1)
          exit(1);
  
        if(!GetThreadContext(hThread, &amp;context))
          exit(1);
  
        printf("Rsp = 0x%x\n", context.Rsp);
  
        if(!GetThreadSelectorEntry(hThread, context.SegGs, &amp;entry)){
          LPSTR buff = NULL;
          FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, 
            GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&amp;buff, 0, NULL);
          printf("Error: %s\n", buff); //ERROR_NOT_SUPPORTED 50 0x32 The request is not supported.
          LocalFree(buff);
          exit(1);
        }
      }
    }
    CloseHandle(hSnapshot);
    return 0;
  }
  </code></pre>
  
  <p>but it's always throwing an error at "GetThreadSelectorEntry". The error code that's thrown is ERROR_NOT_SUPPORTED: The request is not supported.</p>
  
  <p>I am not able to understand why it's not supported. Does anyone know why?</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>Okay GetThreadSelectorEntry is not available to x86_64 processes, does anyone know how I can get the TIB/PEB addresses of a remote process?</p>