~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/mapi/entry_x86-64_tls.h

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
#ifndef MAPI_MODE_BRIDGE
73
73
 
74
74
#include <string.h>
75
 
#include "u_execmem.h"
76
75
 
77
76
void
78
77
entry_patch_public(void)
88
87
   return (mapi_func) (x86_64_entry_start + slot * 32);
89
88
}
90
89
 
91
 
void
92
 
entry_patch(mapi_func entry, int slot)
93
 
{
94
 
   char *code = (char *) entry;
95
 
   int offset = 12;
96
 
#ifdef __ILP32__
97
 
   offset = 13;
98
 
#endif
99
 
   *((unsigned int *) (code + offset)) = slot * sizeof(mapi_func);
100
 
}
101
 
 
102
 
mapi_func
103
 
entry_generate(int slot)
104
 
{
105
 
   const char code_templ[] = {
106
 
#ifndef __ILP32__
107
 
      /* movq %fs:0, %r11 */
108
 
      0x64, 0x4c, 0x8b, 0x1c, 0x25, 0x00, 0x00, 0x00, 0x00,
109
 
      /* jmp *0x1234(%r11) */
110
 
      0x41, 0xff, 0xa3, 0x34, 0x12, 0x00, 0x00,
111
 
#else
112
 
      /* movl %fs:0, %r11d */
113
 
      0x64, 0x44, 0x8b, 0x1c, 0x25, 0x00, 0x00, 0x00, 0x00,
114
 
      /* movl 0x1234(%r11d), %r11d */
115
 
      0x67, 0x45, 0x8b, 0x9b, 0x34, 0x12, 0x00, 0x00,
116
 
      /* jmp *%r11 */
117
 
      0x41, 0xff, 0xe3,
118
 
#endif
119
 
   };
120
 
   unsigned long long addr;
121
 
   char *code;
122
 
   mapi_func entry;
123
 
 
124
 
   __asm__("movq _glapi_tls_Dispatch@GOTTPOFF(%%rip), %0"
125
 
           : "=r" (addr));
126
 
   if ((addr >> 32) != 0xffffffff)
127
 
      return NULL;
128
 
   addr &= 0xffffffff;
129
 
 
130
 
   code = u_execmem_alloc(sizeof(code_templ));
131
 
   if (!code)
132
 
      return NULL;
133
 
 
134
 
   memcpy(code, code_templ, sizeof(code_templ));
135
 
 
136
 
   *((unsigned int *) (code + 5)) = addr;
137
 
   entry = (mapi_func) code;
138
 
   entry_patch(entry, slot);
139
 
 
140
 
   return entry;
141
 
}
142
90
 
143
91
#endif /* MAPI_MODE_BRIDGE */