style: drop unused variables and parameters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
千川白浪andClaude Opus 5.5 committed 2026-12-03 21:31:11 -07:00
1 parent 0ed522656d
commit ab93899f45
10 files changed
+44 -51

No files matched your search

+3 -4
View File
@@ -24,10 +24,9 @@ import (
) )
var ( var (
allDomains = []string{"core", "vm", "wizard", "settings", "plugins", "native", "macos-glossary"} allDomains = []string{"core", "vm", "wizard", "settings", "plugins", "native", "macos-glossary"}
goDomains = []string{"native", "macos-glossary", "core"} goDomains = []string{"native", "macos-glossary", "core"}
feEagerDomains = []string{"core", "vm"} feLazyDomains = []string{"wizard", "settings", "plugins"}
feLazyDomains = []string{"wizard", "settings", "plugins"}
) )
type parsedEntry struct { type parsedEntry struct {
-3
View File
@@ -283,6 +283,3 @@ func suspendProgressPercent(p driver.SuspendProgress) (int, bool) {
} }
return pct, true return pct, true
} }
// Keep context import used cleanly for future cancellation hooks.
var _ context.Context
+9 -9
View File
@@ -303,7 +303,7 @@ func (m *Manager) withConnMode(ctx context.Context, vmDir string, cancelIO bool,
return err return err
} }
nested := m.hasLockScope(ctx, key) nested := m.hasLockScope(ctx, key)
_, release, err := m.acquire(ctx, vmDir) release, err := m.acquire(ctx, vmDir)
if err != nil { if err != nil {
return err return err
} }
@@ -347,7 +347,7 @@ func (m *Manager) withVM(ctx context.Context, vmDir string, operation func(conte
if m.hasLockScope(ctx, key) { if m.hasLockScope(ctx, key) {
return operation(ctx) return operation(ctx)
} }
_, release, err := m.acquire(ctx, vmDir) release, err := m.acquire(ctx, vmDir)
if err != nil { if err != nil {
return err return err
} }
@@ -358,19 +358,19 @@ func (m *Manager) withVM(ctx context.Context, vmDir string, operation func(conte
return operation(context.WithValue(ctx, lockScopeKey{}, scope)) return operation(context.WithValue(ctx, lockScopeKey{}, scope))
} }
func (m *Manager) acquire(ctx context.Context, vmDir string) (*vmLock, func(), error) { func (m *Manager) acquire(ctx context.Context, vmDir string) (func(), error) {
if m == nil { if m == nil {
return nil, nil, errors.New("console manager is unavailable") return nil, errors.New("console manager is unavailable")
} }
if ctx == nil { if ctx == nil {
return nil, nil, errors.New("console context is unavailable") return nil, errors.New("console context is unavailable")
} }
key, err := lockKey(vmDir) key, err := lockKey(vmDir)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if m.hasLockScope(ctx, key) { if m.hasLockScope(ctx, key) {
return &vmLock{}, func() {}, nil return func() {}, nil
} }
m.mu.Lock() m.mu.Lock()
@@ -388,7 +388,7 @@ func (m *Manager) acquire(ctx context.Context, vmDir string) (*vmLock, func(), e
select { select {
case lock.semaphore <- struct{}{}: case lock.semaphore <- struct{}{}:
var once sync.Once var once sync.Once
return lock, func() { return func() {
once.Do(func() { once.Do(func() {
<-lock.semaphore <-lock.semaphore
m.release(key, lock) m.release(key, lock)
@@ -396,7 +396,7 @@ func (m *Manager) acquire(ctx context.Context, vmDir string) (*vmLock, func(), e
}, nil }, nil
case <-ctx.Done(): case <-ctx.Done():
m.release(key, lock) m.release(key, lock)
return nil, nil, ctx.Err() return nil, ctx.Err()
} }
} }
+18 -23
View File
@@ -54,27 +54,25 @@ var (
vcDrawText = user32.NewProc("DrawTextW") vcDrawText = user32.NewProc("DrawTextW")
vcFillRect = user32.NewProc("FillRect") vcFillRect = user32.NewProc("FillRect")
vcGetWindowTextW = user32.NewProc("GetWindowTextW") vcGetWindowTextW = user32.NewProc("GetWindowTextW")
vcInvalidateRect = user32.NewProc("InvalidateRect")
vcSetLayeredAttr = user32.NewProc("SetLayeredWindowAttributes") vcSetLayeredAttr = user32.NewProc("SetLayeredWindowAttributes")
vcSetWindowRgn = user32.NewProc("SetWindowRgn") vcSetWindowRgn = user32.NewProc("SetWindowRgn")
vcBeginPaint = user32.NewProc("BeginPaint") vcBeginPaint = user32.NewProc("BeginPaint")
vcEndPaint = user32.NewProc("EndPaint") vcEndPaint = user32.NewProc("EndPaint")
vcIsWindowEnabled = user32.NewProc("IsWindowEnabled") vcIsWindowEnabled = user32.NewProc("IsWindowEnabled")
vcMoveWindow = user32.NewProc("MoveWindow") vcMoveWindow = user32.NewProc("MoveWindow")
vcGetParent = user32.NewProc("GetParent")
vcSelectObj = vcGDI.NewProc("SelectObject") vcSelectObj = vcGDI.NewProc("SelectObject")
vcStockObj = vcGDI.NewProc("GetStockObject") vcStockObj = vcGDI.NewProc("GetStockObject")
vcDeleteObj = vcGDI.NewProc("DeleteObject") vcDeleteObj = vcGDI.NewProc("DeleteObject")
vcSetDCBrushColor = vcGDI.NewProc("SetDCBrushColor") vcSetDCBrushColor = vcGDI.NewProc("SetDCBrushColor")
vcSetDCPenColor = vcGDI.NewProc("SetDCPenColor") vcSetDCPenColor = vcGDI.NewProc("SetDCPenColor")
vcSetTextColor = vcGDI.NewProc("SetTextColor") vcSetTextColor = vcGDI.NewProc("SetTextColor")
vcSetBkMode = vcGDI.NewProc("SetBkMode") vcSetBkMode = vcGDI.NewProc("SetBkMode")
vcCreateFontW = vcGDI.NewProc("CreateFontIndirectW") vcCreateFontW = vcGDI.NewProc("CreateFontIndirectW")
vcCreateRoundRect = vcGDI.NewProc("CreateRoundRectRgn") vcCreateRoundRect = vcGDI.NewProc("CreateRoundRectRgn")
vcRoundRect = vcGDI.NewProc("RoundRect") vcRoundRect = vcGDI.NewProc("RoundRect")
vcDwmSetWindowAttr = vcDWM.NewProc("DwmSetWindowAttribute") vcDwmSetWindowAttr = vcDWM.NewProc("DwmSetWindowAttribute")
vcRtlMoveMemory = vcKernel.NewProc("RtlMoveMemory") vcRtlMoveMemory = vcKernel.NewProc("RtlMoveMemory")
) )
type vcRect struct{ left, top, right, bottom int32 } type vcRect struct{ left, top, right, bottom int32 }
@@ -116,11 +114,11 @@ type vcLogFont struct {
} }
type vcPalette struct { type vcPalette struct {
surface, border, divider uintptr surface, border, divider uintptr
text, text2, textDisabled uintptr text, text2, textDisabled uintptr
accent, accentPress uintptr accent, accentPress uintptr
btnFill, btnPress, btnBorder uintptr btnFill, btnPress, btnBorder uintptr
dangerText uintptr dangerText uintptr
} }
func vcRGB(r, g, b uint8) uintptr { func vcRGB(r, g, b uint8) uintptr {
@@ -327,7 +325,7 @@ func vcBuildDialogTemplate(title, body, left, right, cancel string, disableRight
style := uint16(0x5000) // WS_CHILD | WS_VISIBLE style := uint16(0x5000) // WS_CHILD | WS_VISIBLE
var ctlStyle uint16 var ctlStyle uint16
if class == clsButton { if class == clsButton {
style |= 1 // WS_TABSTOP style |= 1 // WS_TABSTOP
ctlStyle = 0x0b // BS_OWNERDRAW ctlStyle = 0x0b // BS_OWNERDRAW
if disabled { if disabled {
style |= 0x0800 // WS_DISABLED style |= 0x0800 // WS_DISABLED
@@ -599,6 +597,3 @@ func centerVMCloseDialog(hwnd, owner uintptr) {
procSetWindowPos.Call(hwnd, 0, uintptr(x), uintptr(y), 0, 0, 0x0215) procSetWindowPos.Call(hwnd, 0, uintptr(x), uintptr(y), 0, 0, 0x0215)
} }
} }
var _ = vcGetParent
var _ = vcInvalidateRect
+2 -2
View File
@@ -142,7 +142,7 @@ func (d *ReimsMacOSDriver) prepareStart(ctx context.Context, cfg config.Config,
if err := d.prepareOfflineHelper(cfg, cur, &in); err != nil { if err := d.prepareOfflineHelper(cfg, cur, &in); err != nil {
return in, err return in, err
} }
if err := d.prepareRecoveryBoot(ctx, cfg, c, name, cur.Directory, log); err != nil { if err := d.prepareRecoveryBoot(ctx, c, name, cur.Directory, log); err != nil {
return in, err return in, err
} }
if err := d.prepareGuestLang(ctx, cfg, active, cur.Directory); err != nil { if err := d.prepareGuestLang(ctx, cfg, active, cur.Directory); err != nil {
@@ -178,7 +178,7 @@ func (d *ReimsMacOSDriver) prepareOfflineHelper(cfg config.Config, cur reims.VMD
return nil return nil
} }
func (d *ReimsMacOSDriver) prepareRecoveryBoot(ctx context.Context, cfg config.Config, c *reims.Client, name, vmDir string, log io.Writer) error { func (d *ReimsMacOSDriver) prepareRecoveryBoot(ctx context.Context, c *reims.Client, name, vmDir string, log io.Writer) error {
marker := startprep.ReadRecoveryMarker(vmDir) marker := startprep.ReadRecoveryMarker(vmDir)
if marker != "want" && marker != "restore" { if marker != "want" && marker != "restore" {
return nil return nil
+1 -1
View File
@@ -153,7 +153,7 @@ func (t *translator) inbound(frame []byte) ([]byte, bool) {
return append([]byte(nil), frame...), true return append([]byte(nil), frame...), true
} }
multicast := frame[0]&1 != 0 multicast := frame[0]&1 != 0
deliver := multicast var deliver bool
var multicastMAC net.HardwareAddr var multicastMAC net.HardwareAddr
switch binary.BigEndian.Uint16(frame[12:14]) { switch binary.BigEndian.Uint16(frame[12:14]) {
case 0x0806: case 0x0806:
+8 -5
View File
@@ -181,7 +181,7 @@ func (b *Broker) AuthorizeNetOrigin(pluginID, rawURL string) error {
} }
for _, p := range info.Permissions { for _, p := range info.Permissions {
if netPermissionMatches(p.Name, u) { if netPermissionMatches(p.Name, u) {
if !b.allowRate(pluginID, 120) { if !b.allowRate(pluginID) {
b.Audit(pluginID, "RATE_LIMIT", "net:"+u.Host) b.Audit(pluginID, "RATE_LIMIT", "net:"+u.Host)
return fmt.Errorf("plugin %q exceeded Host API rate limit", pluginID) return fmt.Errorf("plugin %q exceeded Host API rate limit", pluginID)
} }
@@ -242,7 +242,7 @@ func (b *Broker) Authorize(pluginID, perm string) error {
} }
} }
// Rate limit: max 120 Host API calls / second per plugin. // Rate limit: max 120 Host API calls / second per plugin.
if !b.allowRate(pluginID, 120) { if !b.allowRate(pluginID) {
b.Audit(pluginID, "RATE_LIMIT", perm) b.Audit(pluginID, "RATE_LIMIT", perm)
return fmt.Errorf("plugin %q exceeded Host API rate limit", pluginID) return fmt.Errorf("plugin %q exceeded Host API rate limit", pluginID)
} }
@@ -261,14 +261,17 @@ func (b *Broker) AllowRate(pluginID string) error {
if st := b.reg.StateOf(pluginID); st != StateActive && st != StateDegraded { if st := b.reg.StateOf(pluginID); st != StateActive && st != StateDegraded {
return fmt.Errorf("plugin %q is not active (state=%s)", pluginID, st) return fmt.Errorf("plugin %q is not active (state=%s)", pluginID, st)
} }
if !b.allowRate(pluginID, 120) { if !b.allowRate(pluginID) {
b.Audit(pluginID, "RATE_LIMIT", "i18n.getBundle") b.Audit(pluginID, "RATE_LIMIT", "i18n.getBundle")
return fmt.Errorf("plugin %q exceeded Host API rate limit", pluginID) return fmt.Errorf("plugin %q exceeded Host API rate limit", pluginID)
} }
return nil return nil
} }
func (b *Broker) allowRate(pluginID string, limitPerSec int) bool { // hostCallsPerSecond is how many Host API calls one plugin may make per second.
const hostCallsPerSecond = 120
func (b *Broker) allowRate(pluginID string) bool {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
now := time.Now() now := time.Now()
@@ -277,7 +280,7 @@ func (b *Broker) allowRate(pluginID string, limitPerSec int) bool {
b.rates[pluginID] = &rateWindow{windowStart: now, count: 1} b.rates[pluginID] = &rateWindow{windowStart: now, count: 1}
return true return true
} }
if rw.count >= limitPerSec { if rw.count >= hostCallsPerSecond {
return false return false
} }
rw.count++ rw.count++
+2 -2
View File
@@ -88,7 +88,7 @@ func RegisterAll(reg *plugin.Registry, cb HostCallbacks, desiredFn func(id strin
defs := []plugin.PluginDef{ defs := []plugin.PluginDef{
defCore(ver), defCore(ver),
defGuestTools(ver, cb, desiredFn), defGuestTools(ver, cb, desiredFn),
defClipboard(ver, cb, desiredFn), defClipboard(ver, desiredFn),
defInput(ver, cb, desiredFn), defInput(ver, cb, desiredFn),
defNpcapBridge(ver, cb, desiredFn), defNpcapBridge(ver, cb, desiredFn),
defComputerUse(ver, desiredFn), defComputerUse(ver, desiredFn),
@@ -219,7 +219,7 @@ func defGuestTools(ver string, cb HostCallbacks, desiredFn func(string, bool) bo
} }
} }
func defClipboard(ver string, cb HostCallbacks, desiredFn func(string, bool) bool) plugin.PluginDef { func defClipboard(ver string, desiredFn func(string, bool) bool) plugin.PluginDef {
minMB := 1.0 minMB := 1.0
maxMB := 16.0 maxMB := 16.0
minFileMB := float64(guesttools.MinClipboardMaxFileMB) minFileMB := float64(guesttools.MinClipboardMaxFileMB)
-1
View File
@@ -108,7 +108,6 @@ type HookBus struct {
mu sync.RWMutex mu sync.RWMutex
handlers map[string][]*HookRegistration handlers map[string][]*HookRegistration
seq uint64
// Zero-overhead counter for log.onLine (§8.1): checked with atomic load // Zero-overhead counter for log.onLine (§8.1): checked with atomic load
// before constructing LogLineEvent objects. // before constructing LogLineEvent objects.
+1 -1
View File
@@ -314,7 +314,7 @@ func (s *SidecarSupervisor) registerReverseHostAPI(conn *RPCConn) {
conn.Handle("host/audit", func(_ context.Context, raw json.RawMessage) (any, error) { conn.Handle("host/audit", func(_ context.Context, raw json.RawMessage) (any, error) {
if broker != nil { if broker != nil {
if !broker.allowRate(pid, 120) { if !broker.allowRate(pid) {
return nil, fmt.Errorf("plugin %q exceeded audit rate limit", pid) return nil, fmt.Errorf("plugin %q exceeded audit rate limit", pid)
} }
var req struct { var req struct {