@@ -151,6 +151,61 @@ upcall_trace(char const *msg,
151
151
UPCALL_SWITCH_STACK (&args, upcall_s_trace);
152
152
}
153
153
154
+ /* *********************************************************************
155
+ * Allocate an object in the exchange heap
156
+ */
157
+
158
+ struct s_exchange_malloc_args {
159
+ uintptr_t retval;
160
+ type_desc *td;
161
+ };
162
+
163
+ extern " C" CDECL void
164
+ upcall_s_exchange_malloc (s_exchange_malloc_args *args) {
165
+ rust_task *task = rust_get_current_task ();
166
+ LOG_UPCALL_ENTRY (task);
167
+
168
+ LOG (task, mem, " upcall exchange malloc(0x%" PRIxPTR " )" , args->td );
169
+
170
+ // Copied from boxed_region
171
+ size_t header_size = sizeof (rust_opaque_box);
172
+ size_t body_size = args->td ->size ;
173
+ size_t body_align = args->td ->align ;
174
+ size_t total_size = align_to (header_size, body_align) + body_size;
175
+
176
+ void *p = task->kernel ->malloc (total_size, " exchange malloc" );
177
+ memset (p, ' \0 ' , total_size);
178
+
179
+ rust_opaque_box *header = static_cast <rust_opaque_box*>(p);
180
+ header->td = args->td ;
181
+
182
+ args->retval = (uintptr_t )header;
183
+ }
184
+
185
+ extern " C" CDECL uintptr_t
186
+ upcall_exchange_malloc (type_desc *td) {
187
+ s_exchange_malloc_args args = {0 , td};
188
+ UPCALL_SWITCH_STACK (&args, upcall_s_exchange_malloc);
189
+ return args.retval ;
190
+ }
191
+
192
+ struct s_exchange_free_args {
193
+ void *ptr;
194
+ };
195
+
196
+ extern " C" CDECL void
197
+ upcall_s_exchange_free (s_exchange_free_args *args) {
198
+ rust_task *task = rust_get_current_task ();
199
+ LOG_UPCALL_ENTRY (task);
200
+ task->kernel ->free (args->ptr );
201
+ }
202
+
203
+ extern " C" CDECL void
204
+ upcall_exchange_free (void *ptr) {
205
+ s_exchange_free_args args = {ptr};
206
+ UPCALL_SWITCH_STACK (&args, upcall_s_exchange_free);
207
+ }
208
+
154
209
/* *********************************************************************
155
210
* Allocate an object in the task-local heap.
156
211
*/
0 commit comments