github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/custom/names.go (about)

     1  // Package custom is similar to the WebAssembly Custom Sections. These are
     2  // needed because `GOOS=js GOARCH=wasm` functions aren't defined naturally
     3  // in WebAssembly. For example, every function has a single parameter "sp",
     4  // which implicitly maps to stack parameters in this package.
     5  package custom
     6  
     7  const (
     8  	// NamePadding is a marker for a parameter which has no purpose, except
     9  	// padding. It should not be logged.
    10  	NamePadding = "padding"
    11  )
    12  
    13  type Names struct {
    14  	// Name is the WebAssembly function name.
    15  	Name string
    16  
    17  	// ParamNames are the parameters read in 8-byte strides from the stack
    18  	// pointer (SP). This may be nil or include NamePadding.
    19  	ParamNames []string
    20  
    21  	// ResultNames are the results written in 8-byte strides from the stack
    22  	// pointer (SP), after ParamNames.
    23  	ResultNames []string
    24  }
    25  
    26  const (
    27  	NameCallback = "callback"
    28  	NameDebug    = "debug"
    29  )
    30  
    31  const (
    32  	NameRuntimeWasmExit             = "runtime.wasmExit"
    33  	NameRuntimeWasmWrite            = "runtime.wasmWrite"
    34  	NameRuntimeResetMemoryDataView  = "runtime.resetMemoryDataView"
    35  	NameRuntimeNanotime1            = "runtime.nanotime1"
    36  	NameRuntimeWalltime             = "runtime.walltime"
    37  	NameRuntimeScheduleTimeoutEvent = "runtime.scheduleTimeoutEvent"
    38  	NameRuntimeClearTimeoutEvent    = "runtime.clearTimeoutEvent"
    39  	NameRuntimeGetRandomData        = "runtime.getRandomData"
    40  )
    41  
    42  const (
    43  	NameSyscallFinalizeRef        = "syscall/js.finalizeRef"
    44  	NameSyscallStringVal          = "syscall/js.stringVal"
    45  	NameSyscallValueGet           = "syscall/js.valueGet"
    46  	NameSyscallValueSet           = "syscall/js.valueSet"
    47  	NameSyscallValueDelete        = "syscall/js.valueDelete" // stubbed
    48  	NameSyscallValueIndex         = "syscall/js.valueIndex"
    49  	NameSyscallValueSetIndex      = "syscall/js.valueSetIndex" // stubbed
    50  	NameSyscallValueCall          = "syscall/js.valueCall"
    51  	NameSyscallValueInvoke        = "syscall/js.valueInvoke" // stubbed
    52  	NameSyscallValueNew           = "syscall/js.valueNew"
    53  	NameSyscallValueLength        = "syscall/js.valueLength"
    54  	NameSyscallValuePrepareString = "syscall/js.valuePrepareString"
    55  	NameSyscallValueLoadString    = "syscall/js.valueLoadString"
    56  	NameSyscallValueInstanceOf    = "syscall/js.valueInstanceOf" // stubbed
    57  	NameSyscallCopyBytesToGo      = "syscall/js.copyBytesToGo"
    58  	NameSyscallCopyBytesToJS      = "syscall/js.copyBytesToJS"
    59  )
    60  
    61  var NameSection = map[string]*Names{
    62  	NameDebug: {
    63  		Name:        NameDebug,
    64  		ParamNames:  []string{},
    65  		ResultNames: []string{},
    66  	},
    67  
    68  	NameRuntimeWasmExit: {
    69  		Name:        NameRuntimeWasmExit,
    70  		ParamNames:  []string{"code"},
    71  		ResultNames: []string{},
    72  	},
    73  	NameRuntimeWasmWrite: {
    74  		Name:        NameRuntimeWasmWrite,
    75  		ParamNames:  []string{"fd", "p", "p_len"},
    76  		ResultNames: []string{},
    77  	},
    78  	NameRuntimeResetMemoryDataView: {
    79  		Name:        NameRuntimeResetMemoryDataView,
    80  		ParamNames:  []string{},
    81  		ResultNames: []string{},
    82  	},
    83  	NameRuntimeNanotime1: {
    84  		Name:        NameRuntimeNanotime1,
    85  		ParamNames:  []string{},
    86  		ResultNames: []string{"nsec"},
    87  	},
    88  	NameRuntimeWalltime: {
    89  		Name:        NameRuntimeWalltime,
    90  		ParamNames:  []string{},
    91  		ResultNames: []string{"sec", "nsec"},
    92  	},
    93  	NameRuntimeScheduleTimeoutEvent: {
    94  		Name:        NameRuntimeScheduleTimeoutEvent,
    95  		ParamNames:  []string{"ms"},
    96  		ResultNames: []string{"id"},
    97  	},
    98  	NameRuntimeClearTimeoutEvent: {
    99  		Name:        NameRuntimeClearTimeoutEvent,
   100  		ParamNames:  []string{"id"},
   101  		ResultNames: []string{},
   102  	},
   103  	NameRuntimeGetRandomData: {
   104  		Name:        NameRuntimeGetRandomData,
   105  		ParamNames:  []string{"r", "r_len"},
   106  		ResultNames: []string{},
   107  	},
   108  
   109  	NameSyscallFinalizeRef: {
   110  		Name:        NameSyscallFinalizeRef,
   111  		ParamNames:  []string{"r"},
   112  		ResultNames: []string{},
   113  	},
   114  	NameSyscallStringVal: {
   115  		Name:        NameSyscallStringVal,
   116  		ParamNames:  []string{"x", "x_len"},
   117  		ResultNames: []string{"r"},
   118  	},
   119  	NameSyscallValueGet: {
   120  		Name:        NameSyscallValueGet,
   121  		ParamNames:  []string{"v", "p", "p_len"},
   122  		ResultNames: []string{"r"},
   123  	},
   124  	NameSyscallValueSet: {
   125  		Name:        NameSyscallValueSet,
   126  		ParamNames:  []string{"v", "p", "p_len", "x"},
   127  		ResultNames: []string{},
   128  	},
   129  	NameSyscallValueDelete: {
   130  		Name:        NameSyscallValueDelete,
   131  		ParamNames:  []string{"v", "p", "p_len"},
   132  		ResultNames: []string{},
   133  	},
   134  	NameSyscallValueIndex: {
   135  		Name:        NameSyscallValueIndex,
   136  		ParamNames:  []string{"v", "i"},
   137  		ResultNames: []string{"r"},
   138  	},
   139  	NameSyscallValueSetIndex: {
   140  		Name:        NameSyscallValueSetIndex,
   141  		ParamNames:  []string{"v", "i", "x"},
   142  		ResultNames: []string{},
   143  	},
   144  	NameSyscallValueCall: {
   145  		Name:        NameSyscallValueCall,
   146  		ParamNames:  []string{"v", "m", "m_len", "args", "args_len", NamePadding},
   147  		ResultNames: []string{"res", "ok"},
   148  	},
   149  	NameSyscallValueInvoke: {
   150  		Name:        NameSyscallValueInvoke,
   151  		ParamNames:  []string{"v", "args", "args_len", NamePadding},
   152  		ResultNames: []string{"res", "ok"},
   153  	},
   154  	NameSyscallValueNew: {
   155  		Name:        NameSyscallValueNew,
   156  		ParamNames:  []string{"v", "args", "args_len", NamePadding},
   157  		ResultNames: []string{"res", "ok"},
   158  	},
   159  	NameSyscallValueLength: {
   160  		Name:        NameSyscallValueLength,
   161  		ParamNames:  []string{"v"},
   162  		ResultNames: []string{"len"},
   163  	},
   164  	NameSyscallValuePrepareString: {
   165  		Name:        NameSyscallValuePrepareString,
   166  		ParamNames:  []string{"v"},
   167  		ResultNames: []string{"str", "length"},
   168  	},
   169  	NameSyscallValueLoadString: {
   170  		Name:        NameSyscallValueLoadString,
   171  		ParamNames:  []string{"v", "b", "b_len"},
   172  		ResultNames: []string{},
   173  	},
   174  	NameSyscallValueInstanceOf: {
   175  		Name:        NameSyscallValueInstanceOf,
   176  		ParamNames:  []string{"v", "t"},
   177  		ResultNames: []string{"ok"},
   178  	},
   179  	NameSyscallCopyBytesToGo: {
   180  		Name:        NameSyscallCopyBytesToGo,
   181  		ParamNames:  []string{"dst", "dst_len", NamePadding, "src"},
   182  		ResultNames: []string{"n", "ok"},
   183  	},
   184  	NameSyscallCopyBytesToJS: {
   185  		Name:        NameSyscallCopyBytesToJS,
   186  		ParamNames:  []string{"dst", "src", "src_len", NamePadding},
   187  		ResultNames: []string{"n", "ok"},
   188  	},
   189  }
   190  
   191  var NameSectionSyscallValueCall = map[string]map[string]*Names{
   192  	NameCrypto:  CryptoNameSection,
   193  	NameDate:    DateNameSection,
   194  	NameFs:      FsNameSection,
   195  	NameProcess: ProcessNameSection,
   196  }