Enum Class MissingVarGen

java.lang.Object
java.lang.Enum<MissingVarGen>
ghidra.pcode.emu.jit.gen.var.MissingVarGen
All Implemented Interfaces:
ValGen<JitMissingVar>, VarGen<JitMissingVar>, Serializable, Comparable<MissingVarGen>, Constable

public enum MissingVarGen extends Enum<MissingVarGen> implements VarGen<JitMissingVar>
The generator for a missing (local) variable.

In principle, a JitMissingVar should never show up in the use-def graph, since they should all be replaced by phi outputs. We can be certain these should never show up as an output, so we prohibit any attempt to generate code that writes to a missing variable. However, we wait until run time to make that assertion about reads. In theory, it's possible the generator will generate unreachable code that reads from a variable; however, that code is unreachable. First, how does this happen? Second, what if it does?

To answer the first question, we note that the passage decoder should never decode any statically unreachable instructions. However, the p-code emitted by those instructions may technically contain unreachable ops.

To answer the second, we note that the ASM library has a built-in control-flow analyzer, and it ought to detect the unreachable code. In my observation, it replaces that code with nop and/or athrow. Still, in case it doesn't, or in case something changes in a later version (or if/when we port this to the JDK's upcoming classfile API), we emit our own bytecode to throw an AssertionError.

  • Enum Constant Details

  • Method Details

    • values

      public static MissingVarGen[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static MissingVarGen valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • genValInit

      public <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<N> genValInit(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v)
      Description copied from interface: ValGen
      Emit code to prepare any class-level items required to use this variable

      For example, if this represents a direct memory variable, then this can prepare a reference to the portion of the state involved, allowing it to access it readily.

      This should be used to emit code into the constructor.

      Specified by:
      genValInit in interface ValGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the value
      Returns:
      the emitter with ...
    • genReadToStack

      public <THIS extends JitCompiledPassage, T extends Types.BPrim<?>, JT extends JitType.SimpleJitType<T, JT>, N extends Emitter.Next> Emitter<Emitter.Ent<N,T>> genReadToStack(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, JT type, Opnd.Ext ext)
      Description copied from interface: ValGen
      Emit code to read the value onto the stack
      Specified by:
      genReadToStack in interface ValGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      T - the desired JVM type
      JT - the desired p-code type
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the value
      type - the desired p-code type
      ext - the kind of extension to apply
      Returns:
      the emitter with ..., result
    • genReadToOpnd

      public <THIS extends JitCompiledPassage, N extends Emitter.Next> Opnd.OpndEm<JitType.MpIntJitType,N> genReadToOpnd(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope)
      Description copied from interface: ValGen
      Emit code to read the value into local variables

      NOTE: In some cases, this may not emit any code at all. It may simple compose the operand from locals already allocated for a variable being "read."

      Specified by:
      genReadToOpnd in interface ValGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the value
      type - the desired p-code type
      ext - the kind of extension to apply
      scope - a scope for generated temporary variables
      Returns:
      the operand and emitter with ...
    • genReadLegToStack

      public <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<Emitter.Ent<N,Types.TInt>> genReadLegToStack(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, JitType.MpIntJitType type, int leg, Opnd.Ext ext)
      Description copied from interface: ValGen
      Emit code to read a leg of the value onto the stack
      Specified by:
      genReadLegToStack in interface ValGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the value
      type - the desired p-code type
      leg - the leg index, 0 being the least significant
      ext - the kind of extension to apply
      Returns:
      the emitter with ..., result
    • genReadToArray

      public <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<Emitter.Ent<N,Types.TRef<int[]>>> genReadToArray(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope, int slack)
      Description copied from interface: ValGen
      Emit code to read the value into an array
      Specified by:
      genReadToArray in interface ValGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the value
      type - the desired p-code type
      ext - the kind of extension to apply
      scope - a scope for generated temporary variables
      slack - the number of extra (more significant) elements to allocate in the array
      Returns:
      the operand and emitter with ..., arrayref
    • genWriteFromStack

      public <THIS extends JitCompiledPassage, T extends Types.BPrim<?>, JT extends JitType.SimpleJitType<T, JT>, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, T>> Emitter<N1> genWriteFromStack(Emitter<N0> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, JT type, Opnd.Ext ext, Scope scope)
      Description copied from interface: VarGen
      Write a value from a stack operand into the given variable
      Specified by:
      genWriteFromStack in interface VarGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      T - the JVM type of the stack operand
      JT - the p-code type of the stack operand
      N1 - the tail of the stack (...)
      N0 - ..., value
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the variable to write
      type - the p-code type of the stack operand
      ext - the kind of extension to apply when adjusting from varnode size to JVM size
      scope - a scope for temporaries
      Returns:
      the emitter with ...
    • genWriteFromOpnd

      public <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<N> genWriteFromOpnd(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, Opnd<JitType.MpIntJitType> opnd, Opnd.Ext ext, Scope scope)
      Description copied from interface: VarGen
      Write a value from a local operand into the given variable
      Specified by:
      genWriteFromOpnd in interface VarGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the variable to write
      opnd - the source operand
      ext - the kind of extension to apply when adjusting from varnode size to JVM size
      scope - a scope for temporaries
      Returns:
      the emitter with ...
    • genWriteFromArray

      public <THIS extends JitCompiledPassage, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, Types.TRef<int[]>>> Emitter<N1> genWriteFromArray(Emitter<N0> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope)
      Description copied from interface: VarGen
      Write a value from an array operand into the given variable
      Specified by:
      genWriteFromArray in interface VarGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N1 - the tail of the stack (...)
      N0 - ..., arrayref
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the variable to write
      type - the p-code type of the array operand
      ext - the kind of extension to apply when adjusting from varnode size to JVM size
      scope - a scope for temporaries
      Returns:
      the emitter with ...
    • genReadToBool

      public <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<Emitter.Ent<N,Types.TInt>> genReadToBool(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitMissingVar v)
      Description copied from interface: ValGen
      Emit code to read the value onto the stack as a boolean
      Specified by:
      genReadToBool in interface ValGen<JitMissingVar>
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the value
      Returns:
      the emitter with ..., result
    • subpiece

      public ValGen<JitMissingVar> subpiece(int byteShift, int maxByteSize)
      Description copied from interface: ValGen
      Create a generator for a PcodeOp.SUBPIECE of a value.
      Specified by:
      subpiece in interface ValGen<JitMissingVar>
      Parameters:
      byteShift - the number of least-significant bytes to remove
      maxByteSize - the maximum size of the resulting variable. In general, a subpiece should never exceed the size of the parent varnode, but if it does, this will truncate that excess.
      Returns:
      the resulting subpiece generator