v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8::internal::wasm::Decoder Class Reference

#include <decoder.h>

Inheritance diagram for v8::internal::wasm::Decoder:
Collaboration diagram for v8::internal::wasm::Decoder:

Classes

struct  FullValidationTag
 
struct  NoName
 
struct  NoValidationTag
 

Public Types

enum  TraceFlag : bool { kTrace = true , kNoTrace = false }
 
template<typename ValidationTag >
using Name = std::conditional_t<ValidationTag::validate, const char*, NoName>
 

Public Member Functions

 Decoder (const uint8_t *start, const uint8_t *end, uint32_t buffer_offset=0)
 
 Decoder (const base::Vector< const uint8_t > bytes, uint32_t buffer_offset=0)
 
 Decoder (const uint8_t *start, const uint8_t *pc, const uint8_t *end, uint32_t buffer_offset=0)
 
virtual ~Decoder ()=default
 
template<typename ValidationTag >
uint8_t read_u8 (const uint8_t *pc, Name< ValidationTag > msg="expected 1 byte")
 
template<typename ValidationTag >
uint16_t read_u16 (const uint8_t *pc, Name< ValidationTag > msg="expected 2 bytes")
 
template<typename ValidationTag >
uint32_t read_u32 (const uint8_t *pc, Name< ValidationTag > msg="expected 4 bytes")
 
template<typename ValidationTag >
uint64_t read_u64 (const uint8_t *pc, Name< ValidationTag > msg="expected 8 bytes")
 
template<typename ValidationTag >
std::pair< uint32_t, uint32_t > read_u32v (const uint8_t *pc, Name< ValidationTag > name="LEB32")
 
template<typename ValidationTag >
std::pair< int32_t, uint32_t > read_i32v (const uint8_t *pc, Name< ValidationTag > name="signed LEB32")
 
template<typename ValidationTag >
std::pair< uint64_t, uint32_t > read_u64v (const uint8_t *pc, Name< ValidationTag > name="LEB64")
 
template<typename ValidationTag >
std::pair< int64_t, uint32_t > read_i64v (const uint8_t *pc, Name< ValidationTag > name="signed LEB64")
 
template<typename ValidationTag >
std::pair< int64_t, uint32_t > read_i33v (const uint8_t *pc, Name< ValidationTag > name="signed LEB33")
 
template<typename ValidationTag >
std::pair< WasmOpcode, uint32_t > read_prefixed_opcode (const uint8_t *pc, Name< ValidationTag > name="prefixed opcode")
 
uint8_t consume_u8 (const char *name="uint8_t")
 
uint8_t consume_u8 (const char *name, ITracer *tracer)
 
uint16_t consume_u16 (const char *name="uint16_t")
 
uint32_t consume_u32 (const char *name, ITracer *tracer)
 
uint32_t consume_u32v (const char *name="var_uint32")
 
uint32_t consume_u32v (const char *name, ITracer *tracer)
 
int32_t consume_i32v (const char *name="var_int32")
 
uint64_t consume_u64v (const char *name, ITracer *tracer)
 
int64_t consume_i64v (const char *name="var_int64")
 
void consume_bytes (uint32_t size, const char *name="skip")
 
void consume_bytes (uint32_t size, const char *name, ITracer *tracer)
 
uint32_t available_bytes () const
 
bool checkAvailable (uint32_t size)
 
void V8_NOINLINE V8_PRESERVE_MOST error (const char *msg)
 
void V8_NOINLINE V8_PRESERVE_MOST error (const uint8_t *pc, const char *msg)
 
void V8_NOINLINE V8_PRESERVE_MOST error (uint32_t offset, const char *msg)
 
template<typename... Args>
void V8_NOINLINE V8_PRESERVE_MOST errorf (const char *format, Args... args)
 
template<typename... Args>
void V8_NOINLINE V8_PRESERVE_MOST errorf (const uint8_t *pc, const char *format, Args... args)
 
template<typename... Args>
void V8_NOINLINE V8_PRESERVE_MOST errorf (uint32_t offset, const char *format, Args... args)
 
virtual void onFirstError ()
 
void traceByteRange (const uint8_t *start, const uint8_t *end)
 
void traceOffEnd ()
 
template<typename T , typename R = std::decay_t<T>>
Result< R > toResult (T &&val)
 
void Reset (const uint8_t *start, const uint8_t *end, uint32_t buffer_offset=0)
 
void Reset (base::Vector< const uint8_t > bytes, uint32_t buffer_offset=0)
 
bool ok () const
 
bool failed () const
 
bool more () const
 
const WasmErrorerror () const
 
const uint8_t * start () const
 
const uint8_t * pc () const
 
uint32_t V8_INLINE position () const
 
uint32_t V8_INLINE pc_offset (const uint8_t *pc) const
 
uint32_t pc_offset () const
 
uint32_t buffer_offset () const
 
uint32_t GetBufferRelativeOffset (uint32_t offset) const
 
const uint8_t * end () const
 
void set_end (const uint8_t *end)
 
bool lookahead (int offset, uint8_t expected)
 

Static Public Attributes

static constexpr struct v8::internal::wasm::Decoder::NoValidationTag kNoValidation = {}
 
static constexpr struct v8::internal::wasm::Decoder::FullValidationTag kFullValidation = {}
 

Protected Attributes

const uint8_t * start_
 
const uint8_t * pc_
 
const uint8_t * end_
 
uint32_t buffer_offset_
 
WasmError error_
 

Private Member Functions

void V8_NOINLINE PRINTF_FORMAT (3, 4) verrorf(uint32_t offset
 
 va_start (args, format)
 
 va_end (args)
 
 CHECK_LT (0, len)
 
 onFirstError ()
 
template<typename IntType , typename ValidationTag >
IntType read_little_endian (const uint8_t *pc, Name< ValidationTag > msg)
 
template<typename IntType , TraceFlag trace>
IntType consume_little_endian (const char *name)
 
template<typename IntType , typename ValidationTag , TraceFlag trace, size_t size_in_bits = 8 * sizeof(IntType)>
V8_INLINE std::pair< IntType, uint32_t > read_leb (const uint8_t *pc, Name< ValidationTag > name="varint")
 
template<typename IntType , typename ValidationTag , TraceFlag trace, size_t size_in_bits = 8 * sizeof(IntType)>
V8_NOINLINE V8_PRESERVE_MOST std::pair< IntType, uint32_t > read_leb_slowpath (const uint8_t *pc, Name< ValidationTag > name)
 
template<typename IntType , typename ValidationTag , TraceFlag trace, size_t size_in_bits, int byte_index>
V8_INLINE std::pair< IntType, uint32_t > read_leb_tail (const uint8_t *pc, Name< ValidationTag > name, IntType intermediate_result)
 

Private Attributes

void V8_NOINLINE const char * format
 
void V8_NOINLINE const char constexpr int kMaxErrorMsg = 256
 
base::EmbeddedVector< char, kMaxErrorMsgbuffer
 
va_list args
 
int len = base::VSNPrintF(buffer, format, args)
 
 error_ = {offset, {buffer.begin(), static_cast<size_t>(len)}}
 

Detailed Description

Definition at line 88 of file decoder.h.

Member Typedef Documentation

◆ Name

template<typename ValidationTag >
using v8::internal::wasm::Decoder::Name = std::conditional_t<ValidationTag::validate, const char*, NoName>

Definition at line 110 of file decoder.h.

Member Enumeration Documentation

◆ TraceFlag

Enumerator
kTrace 
kNoTrace 

Definition at line 113 of file decoder.h.

Constructor & Destructor Documentation

◆ Decoder() [1/3]

v8::internal::wasm::Decoder::Decoder ( const uint8_t * start,
const uint8_t * end,
uint32_t buffer_offset = 0 )
inline

Definition at line 115 of file decoder.h.

◆ Decoder() [2/3]

v8::internal::wasm::Decoder::Decoder ( const base::Vector< const uint8_t > bytes,
uint32_t buffer_offset = 0 )
inlineexplicit

Definition at line 117 of file decoder.h.

◆ Decoder() [3/3]

v8::internal::wasm::Decoder::Decoder ( const uint8_t * start,
const uint8_t * pc,
const uint8_t * end,
uint32_t buffer_offset = 0 )
inline

Definition at line 120 of file decoder.h.

Here is the call graph for this function:

◆ ~Decoder()

virtual v8::internal::wasm::Decoder::~Decoder ( )
virtualdefault

Member Function Documentation

◆ available_bytes()

uint32_t v8::internal::wasm::Decoder::available_bytes ( ) const
inline

Definition at line 314 of file decoder.h.

Here is the caller graph for this function:

◆ buffer_offset()

uint32_t v8::internal::wasm::Decoder::buffer_offset ( ) const
inline

Definition at line 419 of file decoder.h.

Here is the caller graph for this function:

◆ CHECK_LT()

v8::internal::wasm::Decoder::CHECK_LT ( 0 ,
len  )
private

◆ checkAvailable()

bool v8::internal::wasm::Decoder::checkAvailable ( uint32_t size)
inline

Definition at line 321 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_bytes() [1/2]

void v8::internal::wasm::Decoder::consume_bytes ( uint32_t size,
const char * name,
ITracer * tracer )
inline

Definition at line 306 of file decoder.h.

Here is the call graph for this function:

◆ consume_bytes() [2/2]

void v8::internal::wasm::Decoder::consume_bytes ( uint32_t size,
const char * name = "skip" )
inline

Definition at line 297 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_i32v()

int32_t v8::internal::wasm::Decoder::consume_i32v ( const char * name = "var_int32")
inline

Definition at line 269 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_i64v()

int64_t v8::internal::wasm::Decoder::consume_i64v ( const char * name = "var_int64")
inline

Definition at line 289 of file decoder.h.

Here is the call graph for this function:

◆ consume_little_endian()

template<typename IntType , TraceFlag trace>
IntType v8::internal::wasm::Decoder::consume_little_endian ( const char * name)
inlineprivate

Definition at line 474 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_u16()

uint16_t v8::internal::wasm::Decoder::consume_u16 ( const char * name = "uint16_t")
inline

Definition at line 237 of file decoder.h.

Here is the call graph for this function:

◆ consume_u32()

uint32_t v8::internal::wasm::Decoder::consume_u32 ( const char * name,
ITracer * tracer )
inline

Definition at line 242 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_u32v() [1/2]

uint32_t v8::internal::wasm::Decoder::consume_u32v ( const char * name,
ITracer * tracer )
inline

Definition at line 257 of file decoder.h.

Here is the call graph for this function:

◆ consume_u32v() [2/2]

uint32_t v8::internal::wasm::Decoder::consume_u32v ( const char * name = "var_uint32")
inline

Definition at line 251 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_u64v()

uint64_t v8::internal::wasm::Decoder::consume_u64v ( const char * name,
ITracer * tracer )
inline

Definition at line 277 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_u8() [1/2]

uint8_t v8::internal::wasm::Decoder::consume_u8 ( const char * name,
ITracer * tracer )
inline

Definition at line 228 of file decoder.h.

Here is the call graph for this function:

◆ consume_u8() [2/2]

uint8_t v8::internal::wasm::Decoder::consume_u8 ( const char * name = "uint8_t")
inline

Definition at line 225 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

const uint8_t * v8::internal::wasm::Decoder::end ( ) const
inline

Definition at line 426 of file decoder.h.

Here is the caller graph for this function:

◆ error() [1/4]

const WasmError & v8::internal::wasm::Decoder::error ( ) const
inline

Definition at line 405 of file decoder.h.

Here is the caller graph for this function:

◆ error() [2/4]

void V8_NOINLINE V8_PRESERVE_MOST v8::internal::wasm::Decoder::error ( const char * msg)
inline

Definition at line 331 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error() [3/4]

void V8_NOINLINE V8_PRESERVE_MOST v8::internal::wasm::Decoder::error ( const uint8_t * pc,
const char * msg )
inline

Definition at line 334 of file decoder.h.

Here is the call graph for this function:

◆ error() [4/4]

void V8_NOINLINE V8_PRESERVE_MOST v8::internal::wasm::Decoder::error ( uint32_t offset,
const char * msg )
inline

Definition at line 337 of file decoder.h.

Here is the call graph for this function:

◆ errorf() [1/3]

template<typename... Args>
void V8_NOINLINE V8_PRESERVE_MOST v8::internal::wasm::Decoder::errorf ( const char * format,
Args... args )
inline

Definition at line 342 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ errorf() [2/3]

template<typename... Args>
void V8_NOINLINE V8_PRESERVE_MOST v8::internal::wasm::Decoder::errorf ( const uint8_t * pc,
const char * format,
Args... args )
inline

Definition at line 347 of file decoder.h.

Here is the call graph for this function:

◆ errorf() [3/3]

template<typename... Args>
void V8_NOINLINE V8_PRESERVE_MOST v8::internal::wasm::Decoder::errorf ( uint32_t offset,
const char * format,
Args... args )
inline

Definition at line 353 of file decoder.h.

◆ failed()

bool v8::internal::wasm::Decoder::failed ( ) const
inline

Definition at line 403 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBufferRelativeOffset()

uint32_t v8::internal::wasm::Decoder::GetBufferRelativeOffset ( uint32_t offset) const
inline

Definition at line 422 of file decoder.h.

Here is the caller graph for this function:

◆ lookahead()

bool v8::internal::wasm::Decoder::lookahead ( int offset,
uint8_t expected )
inline

Definition at line 430 of file decoder.h.

Here is the caller graph for this function:

◆ more()

bool v8::internal::wasm::Decoder::more ( ) const
inline

Definition at line 404 of file decoder.h.

Here is the caller graph for this function:

◆ ok()

bool v8::internal::wasm::Decoder::ok ( ) const
inline

Definition at line 402 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onFirstError() [1/2]

virtual void v8::internal::wasm::Decoder::onFirstError ( )
inlinevirtual

◆ onFirstError() [2/2]

v8::internal::wasm::Decoder::onFirstError ( )
private

◆ pc()

const uint8_t * v8::internal::wasm::Decoder::pc ( ) const
inline

Definition at line 408 of file decoder.h.

◆ pc_offset() [1/2]

uint32_t v8::internal::wasm::Decoder::pc_offset ( ) const
inline

Definition at line 418 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pc_offset() [2/2]

uint32_t V8_INLINE v8::internal::wasm::Decoder::pc_offset ( const uint8_t * pc) const
inline

Definition at line 413 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ position()

uint32_t V8_INLINE v8::internal::wasm::Decoder::position ( ) const
inline

Definition at line 409 of file decoder.h.

◆ PRINTF_FORMAT()

void V8_NOINLINE v8::internal::wasm::Decoder::PRINTF_FORMAT ( 3 ,
4  )
private

◆ read_i32v()

template<typename ValidationTag >
std::pair< int32_t, uint32_t > v8::internal::wasm::Decoder::read_i32v ( const uint8_t * pc,
Name< ValidationTag > name = "signed LEB32" )
inline

Definition at line 169 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_i33v()

template<typename ValidationTag >
std::pair< int64_t, uint32_t > v8::internal::wasm::Decoder::read_i33v ( const uint8_t * pc,
Name< ValidationTag > name = "signed LEB33" )
inline

Definition at line 193 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_i64v()

template<typename ValidationTag >
std::pair< int64_t, uint32_t > v8::internal::wasm::Decoder::read_i64v ( const uint8_t * pc,
Name< ValidationTag > name = "signed LEB64" )
inline

Definition at line 185 of file decoder.h.

Here is the call graph for this function:

◆ read_leb()

template<typename IntType , typename ValidationTag , TraceFlag trace, size_t size_in_bits = 8 * sizeof(IntType)>
V8_INLINE std::pair< IntType, uint32_t > v8::internal::wasm::Decoder::read_leb ( const uint8_t * pc,
Name< ValidationTag > name = "varint" )
inlineprivate

Definition at line 492 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_leb_slowpath()

template<typename IntType , typename ValidationTag , TraceFlag trace, size_t size_in_bits = 8 * sizeof(IntType)>
V8_NOINLINE V8_PRESERVE_MOST std::pair< IntType, uint32_t > v8::internal::wasm::Decoder::read_leb_slowpath ( const uint8_t * pc,
Name< ValidationTag > name )
inlineprivate

Definition at line 522 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_leb_tail()

template<typename IntType , typename ValidationTag , TraceFlag trace, size_t size_in_bits, int byte_index>
V8_INLINE std::pair< IntType, uint32_t > v8::internal::wasm::Decoder::read_leb_tail ( const uint8_t * pc,
Name< ValidationTag > name,
IntType intermediate_result )
inlineprivate

Definition at line 531 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_little_endian()

template<typename IntType , typename ValidationTag >
IntType v8::internal::wasm::Decoder::read_little_endian ( const uint8_t * pc,
Name< ValidationTag > msg )
inlineprivate

Definition at line 460 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_prefixed_opcode()

template<typename ValidationTag >
std::pair< WasmOpcode, uint32_t > v8::internal::wasm::Decoder::read_prefixed_opcode ( const uint8_t * pc,
Name< ValidationTag > name = "prefixed opcode" )
inline

Definition at line 202 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_u16()

template<typename ValidationTag >
uint16_t v8::internal::wasm::Decoder::read_u16 ( const uint8_t * pc,
Name< ValidationTag > msg = "expected 2 bytes" )
inline

Definition at line 139 of file decoder.h.

Here is the call graph for this function:

◆ read_u32()

template<typename ValidationTag >
uint32_t v8::internal::wasm::Decoder::read_u32 ( const uint8_t * pc,
Name< ValidationTag > msg = "expected 4 bytes" )
inline

Definition at line 146 of file decoder.h.

Here is the call graph for this function:

◆ read_u32v()

template<typename ValidationTag >
std::pair< uint32_t, uint32_t > v8::internal::wasm::Decoder::read_u32v ( const uint8_t * pc,
Name< ValidationTag > name = "LEB32" )
inline

Definition at line 161 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_u64()

template<typename ValidationTag >
uint64_t v8::internal::wasm::Decoder::read_u64 ( const uint8_t * pc,
Name< ValidationTag > msg = "expected 8 bytes" )
inline

Definition at line 153 of file decoder.h.

Here is the call graph for this function:

◆ read_u64v()

template<typename ValidationTag >
std::pair< uint64_t, uint32_t > v8::internal::wasm::Decoder::read_u64v ( const uint8_t * pc,
Name< ValidationTag > name = "LEB64" )
inline

Definition at line 177 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_u8()

template<typename ValidationTag >
uint8_t v8::internal::wasm::Decoder::read_u8 ( const uint8_t * pc,
Name< ValidationTag > msg = "expected 1 byte" )
inline

Definition at line 132 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reset() [1/2]

void v8::internal::wasm::Decoder::Reset ( base::Vector< const uint8_t > bytes,
uint32_t buffer_offset = 0 )
inline

Definition at line 398 of file decoder.h.

Here is the call graph for this function:

◆ Reset() [2/2]

void v8::internal::wasm::Decoder::Reset ( const uint8_t * start,
const uint8_t * end,
uint32_t buffer_offset = 0 )
inline

Definition at line 387 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_end()

void v8::internal::wasm::Decoder::set_end ( const uint8_t * end)
inline

Definition at line 427 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

const uint8_t * v8::internal::wasm::Decoder::start ( ) const
inline

Definition at line 407 of file decoder.h.

Here is the caller graph for this function:

◆ toResult()

template<typename T , typename R = std::decay_t<T>>
Result< R > v8::internal::wasm::Decoder::toResult ( T && val)
inline

Definition at line 378 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ traceByteRange()

void v8::internal::wasm::Decoder::traceByteRange ( const uint8_t * start,
const uint8_t * end )
inline

Definition at line 365 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ traceOffEnd()

void v8::internal::wasm::Decoder::traceOffEnd ( )
inline

Definition at line 371 of file decoder.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ va_end()

v8::internal::wasm::Decoder::va_end ( args )
private

◆ va_start()

v8::internal::wasm::Decoder::va_start ( args ,
format  )
private

Member Data Documentation

◆ args

va_list v8::internal::wasm::Decoder::args
private

Definition at line 450 of file decoder.h.

◆ buffer

base::EmbeddedVector<char, kMaxErrorMsg> v8::internal::wasm::Decoder::buffer
private

Definition at line 449 of file decoder.h.

◆ buffer_offset_

uint32_t v8::internal::wasm::Decoder::buffer_offset_
protected

Definition at line 440 of file decoder.h.

◆ end_

const uint8_t* v8::internal::wasm::Decoder::end_
protected

Definition at line 438 of file decoder.h.

◆ error_ [1/2]

WasmError v8::internal::wasm::Decoder::error_
protected

Definition at line 441 of file decoder.h.

◆ error_ [2/2]

v8::internal::wasm::Decoder::error_ = {offset, {buffer.begin(), static_cast<size_t>(len)}}
private

Definition at line 455 of file decoder.h.

◆ format

void V8_NOINLINE const char* v8::internal::wasm::Decoder::format
private

Definition at line 445 of file decoder.h.

◆ kFullValidation

struct v8::internal::wasm::Decoder::FullValidationTag v8::internal::wasm::Decoder::kFullValidation = {}
static

◆ kMaxErrorMsg

void V8_NOINLINE const char constexpr int v8::internal::wasm::Decoder::kMaxErrorMsg = 256
constexprprivate

Definition at line 448 of file decoder.h.

◆ kNoValidation

struct v8::internal::wasm::Decoder::NoValidationTag v8::internal::wasm::Decoder::kNoValidation = {}
static

◆ len

int v8::internal::wasm::Decoder::len = base::VSNPrintF(buffer, format, args)
private

Definition at line 452 of file decoder.h.

◆ pc_

const uint8_t* v8::internal::wasm::Decoder::pc_
protected

Definition at line 437 of file decoder.h.

◆ start_

const uint8_t* v8::internal::wasm::Decoder::start_
protected

Definition at line 436 of file decoder.h.


The documentation for this class was generated from the following file: