Skip to content

Commit

Permalink
cannon: Only allow gc patching for single-threaded Cannon
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaxter committed Sep 19, 2024
1 parent 22e705a commit 1760d3b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cannon/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ func vmTypeFromString(ctx *cli.Context) (VMType, error) {
func LoadELF(ctx *cli.Context) error {
var createInitialState func(f *elf.File) (mipsevm.FPVMState, error)

allowGoGCPatch := false
if vmType, err := vmTypeFromString(ctx); err != nil {
return err
} else if vmType == cannonVMType {
allowGoGCPatch = true
createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) {
return program.LoadELF(f, singlethreaded.CreateInitialState)
}
Expand Down Expand Up @@ -99,7 +101,11 @@ func LoadELF(ctx *cli.Context) error {
case "stack":
err = program.PatchStack(state)
case "go":
err = program.PatchGoGC(elfProgram, state)
if allowGoGCPatch {
err = program.PatchGoGC(elfProgram, state)
} else {
err = fmt.Errorf("patch type %q not allowed for vm type %q", typ, ctx.String(LoadELFVMTypeFlag.Name))
}
default:
return fmt.Errorf("unrecognized form of patching: %q", typ)
}
Expand Down

0 comments on commit 1760d3b

Please sign in to comment.