From 0ef7f1d2d6f76ca3111cdbc59d4ae0038f61c2aa Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 21 Mar 2020 21:22:20 -0700 Subject: 6160 - plan for safe heap access Based on apps/handle.subx (commit 4894), but we're able to simplify it further now that we know more about the situation we find ourselves in. 6 instructions, zero pushes or pops. Before I can start building this, I need to reorganize my use of handles. They're going to be fat pointers so we can't store them in registers anymore. --- mu_summary | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'mu_summary') diff --git a/mu_summary b/mu_summary index d098d28f..1ac7a086 100644 --- a/mu_summary +++ b/mu_summary @@ -216,3 +216,27 @@ Similarly, conditional loops: var/reg: (addr T_f) <- get var/reg: (addr T), f where record (product) type T has elements a, b, c, ... of types T_a, T_b, T_c, ... var/reg: (addr T_f) <- get var: (addr T), f + +## Handles for safe access to the heap + +Say we created a handle like this on the stack (it can't be in a register) + var x: (handle T) + allocate Heap, T, x + +You can copy handles to another variable on the stack like this: + var y: (handle T) + copy-handle-to y, x + +You can also save handles inside other user-defined types like this: + var y/reg: (addr handle T_f) <- get var: (addr T), f + copy-handle-to *y, x + +Or this: + var y/reg: (addr handle T) <- index arr: (addr array handle T), n + copy-handle-to *y, x + +Handles can be converted into addresses like this: + var y/reg: (addr T) <- lookup x + +It's illegal to continue to use this addr after a function that reclaims heap +memory. You have to repeat the lookup. -- cgit 1.4.1-2-gfad0 327a7b6915cf2c4784744b8e4b7b77169'>commit diff stats
path: root/linux/ex7.subx
blob: ad1a50b64571aaa5ebd6769f1e901c807c982230 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98