38 lines
974 B
Go
38 lines
974 B
Go
package runtime
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"runtime"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/host"
|
|
)
|
|
|
|
// CheckLaunchASLR repairs the selected runtime's rule after a data folder
|
|
// move and avoids reactivating a version superseded during launch prep.
|
|
func CheckLaunchASLR(ctx context.Context, cfg config.Config, qemuPath string) error {
|
|
if runtime.GOOS != "windows" {
|
|
return ctx.Err()
|
|
}
|
|
if err := RefreshSelection(&cfg); err != nil || !cfg.QEMUASLR {
|
|
return err
|
|
}
|
|
release, err := lockRuntimeDirectories(cfg.RuntimesDir())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer release()
|
|
if err := RefreshSelection(&cfg); err != nil || !cfg.QEMUASLR {
|
|
return err
|
|
}
|
|
activePath, err := qemuASLRPath(&cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if activePath == "" || !samePath(activePath, qemuPath) {
|
|
return errors.New("active runtime changed during VM start")
|
|
}
|
|
return host.SyncQEMUASLR(ctx, cfg.RuntimesDir(), activePath)
|
|
}
|