[BACK]Return to patch.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / x86 / x86

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/arch/x86/x86/patch.c between version 1.24 and 1.25

version 1.24, 2017/10/27 23:22:01 version 1.25, 2018/01/07 11:24:45
Line 130  patchfunc(void *from_s, void *from_e, vo
Line 130  patchfunc(void *from_s, void *from_e, vo
 }  }
   
 static inline void __unused  static inline void __unused
 patchbytes(void *addr, const int byte1, const int byte2, const int byte3)  patchbytes(void *addr, const uint8_t *bytes, size_t size)
 {  {
           uint8_t *ptr = (uint8_t *)addr;
           size_t i;
   
         ((uint8_t *)addr)[0] = (uint8_t)byte1;          for (i = 0; i < size; i++) {
         if (byte2 != -1)                  ptr[i] = bytes[i];
                 ((uint8_t *)addr)[1] = (uint8_t)byte2;          }
         if (byte3 != -1)  
                 ((uint8_t *)addr)[2] = (uint8_t)byte3;  
 }  }
   
 void  void
Line 169  x86_patch(bool early)
Line 169  x86_patch(bool early)
 #if !defined(GPROF)  #if !defined(GPROF)
         if (!early && ncpu == 1) {          if (!early && ncpu == 1) {
 #ifndef LOCKDEBUG  #ifndef LOCKDEBUG
                   const uint8_t bytes[] = {
                           X86_NOP
                   };
   
                 /* Uniprocessor: kill LOCK prefixes. */                  /* Uniprocessor: kill LOCK prefixes. */
                 for (i = 0; x86_lockpatch[i] != 0; i++)                  for (i = 0; x86_lockpatch[i] != 0; i++)
                         patchbytes(x86_lockpatch[i], X86_NOP, -1, -1);                          patchbytes(x86_lockpatch[i], bytes, sizeof(bytes));
                 for (i = 0; atomic_lockpatch[i] != 0; i++)                  for (i = 0; atomic_lockpatch[i] != 0; i++)
                         patchbytes(atomic_lockpatch[i], X86_NOP, -1, -1);                          patchbytes(atomic_lockpatch[i], bytes, sizeof(bytes));
 #endif  /* !LOCKDEBUG */  #endif  /* !LOCKDEBUG */
         }          }
         if (!early && (cpu_feature[0] & CPUID_SSE2) != 0) {          if (!early && (cpu_feature[0] & CPUID_SSE2) != 0) {
Line 237  x86_patch(bool early)
Line 241  x86_patch(bool early)
             (CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xe ||              (CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xe ||
             (CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xf &&              (CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xf &&
             CPUID_TO_EXTMODEL(cpu_info_primary.ci_signature) < 0x4))) {              CPUID_TO_EXTMODEL(cpu_info_primary.ci_signature) < 0x4))) {
                   const uint8_t bytes[] = {
                           0x0F, 0xAE, 0xE8 /* lfence */
                   };
   
                 for (i = 0; x86_retpatch[i] != 0; i++) {                  for (i = 0; x86_retpatch[i] != 0; i++) {
                         /* ret,nop,nop,ret -> lfence,ret */                          /* ret,nop,nop,ret -> lfence,ret */
                         patchbytes(x86_retpatch[i], 0x0f, 0xae, 0xe8);                          patchbytes(x86_retpatch[i], bytes, sizeof(bytes));
                 }                  }
         }          }
   
Line 253  x86_patch(bool early)
Line 261  x86_patch(bool early)
          */           */
         if (!early && cpu_feature[5] & CPUID_SEF_SMAP) {          if (!early && cpu_feature[5] & CPUID_SEF_SMAP) {
                 KASSERT(rcr4() & CR4_SMAP);                  KASSERT(rcr4() & CR4_SMAP);
                   const uint8_t clac_bytes[] = {
                           0x0F, 0x01, 0xCA /* clac */
                   };
                   const uint8_t stac_bytes[] = {
                           0x0F, 0x01, 0xCB /* stac */
                   };
   
                 for (i = 0; x86_clacpatch[i] != NULL; i++) {                  for (i = 0; x86_clacpatch[i] != NULL; i++) {
                         /* ret,int3,int3 -> clac */                          /* ret,int3,int3 -> clac */
                         patchbytes(x86_clacpatch[i],                          patchbytes(x86_clacpatch[i], clac_bytes,
                             0x0f, 0x01, 0xca);                              sizeof(clac_bytes));
                 }                  }
                 for (i = 0; x86_stacpatch[i] != NULL; i++) {                  for (i = 0; x86_stacpatch[i] != NULL; i++) {
                         /* ret,int3,int3 -> stac */                          /* ret,int3,int3 -> stac */
                         patchbytes(x86_stacpatch[i],                          patchbytes(x86_stacpatch[i], stac_bytes,
                             0x0f, 0x01, 0xcb);                              sizeof(stac_bytes));
                 }                  }
         }          }
 #endif  #endif

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

CVSweb <webmaster@jp.NetBSD.org>