跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

memory_darwin.go

43 行 · 1.3 KB历史下载
1//go:build darwin && !no_vz
2
3// SPDX-FileCopyrightText: Copyright The Lima Authors
4// SPDX-License-Identifier: Apache-2.0
5
6package vz
7
8import (
9 "context"
10 "errors"
11 "runtime"
12
13 "github.com/Code-Hex/vz/v3"
14 "github.com/docker/go-units"
15)
16
17func (l *LimaVzDriver) SetMemoryTarget(ctx context.Context, target uint64) error {
18 if err := ctx.Err(); err != nil {
19 return err
20 }
21 maximum, err := units.RAMInBytes(*l.Instance.Config.Memory)
22 if err != nil {
23 return err
24 }
25 if target < 512<<20 || target > uint64(maximum) || target%(1<<20) != 0 {
26 return errors.New("memory target is outside the VM capacity")
27 }
28 if l.machine == nil || l.machine.State() != vz.VirtualMachineStateRunning {
29 return errors.New("VM is not running")
30 }
31 for _, device := range l.machine.MemoryBalloonDevices() {
32 if balloon := vz.AsVirtioTraditionalMemoryBalloonDevice(device); balloon != nil {
33 // go-vz v3.7.1 wraps a borrowed NSArray member without retaining it,
34 // but installs a releasing finalizer. The VM owns this native device.
35 // Do not let temporary wrappers release the VM's reference.
36 runtime.SetFinalizer(balloon, nil)
37 balloon.SetTargetVirtualMachineMemorySize(target)
38 runtime.KeepAlive(l.machine)
39 return nil
40 }
41 }
42 return errors.New("memory balloon is unavailable")
43}