Memory resolves and returns the memory from the path p.
(ctx context.Context, p *path.Memory, rc *path.ResolveConfig)
| 30 | |
| 31 | // Memory resolves and returns the memory from the path p. |
| 32 | func Memory(ctx context.Context, p *path.Memory, rc *path.ResolveConfig) (*service.Memory, error) { |
| 33 | ctx = SetupContext(ctx, path.FindCapture(p), rc) |
| 34 | |
| 35 | cmdIdx := p.After.Indices[0] |
| 36 | fullCmdIdx := p.After.Indices |
| 37 | |
| 38 | allCmds, err := Cmds(ctx, path.FindCapture(p)) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | if count := uint64(len(allCmds)); cmdIdx >= count { |
| 44 | return nil, errPathOOB(cmdIdx, "Index", 0, count-1, p) |
| 45 | } |
| 46 | |
| 47 | sd, err := SyncData(ctx, path.FindCapture(p)) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | cmds, err := sync.MutationCmdsFor(ctx, path.FindCapture(p), sd, allCmds, api.CmdID(cmdIdx), fullCmdIdx[1:], true) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | |
| 57 | defer analytics.SendTiming("resolve", "memory")(analytics.Count(len(cmds))) |
| 58 | |
| 59 | s, err := capture.NewState(ctx) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | err = api.ForeachCmd(ctx, cmds[:len(cmds)-1], func(ctx context.Context, id api.CmdID, cmd api.Cmd) error { |
| 64 | cmd.Mutate(ctx, id, s, nil, nil) |
| 65 | return nil |
| 66 | }) |
| 67 | if err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | |
| 71 | r := memory.Range{Base: p.Address, Size: p.Size} |
| 72 | var reads, writes, observed memory.RangeList |
| 73 | s.Memory.SetOnCreate(func(id memory.PoolID, pool *memory.Pool) { |
| 74 | if id == memory.PoolID(p.Pool) { |
| 75 | pool.OnRead = func(rng memory.Range) { |
| 76 | if rng.Overlaps(r) { |
| 77 | interval.Merge(&reads, rng.Window(r).Span(), false) |
| 78 | } |
| 79 | } |
| 80 | pool.OnWrite = func(rng memory.Range) { |
| 81 | if rng.Overlaps(r) { |
| 82 | interval.Merge(&writes, rng.Window(r).Span(), false) |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | }) |
| 87 | |
| 88 | lastCmd := cmds[len(cmds)-1] |
| 89 | api.MutateCmds(ctx, s, nil, nil, lastCmd) |
no test coverage detected