@@ -155,31 +155,38 @@ upcall_trace(char const *msg,
155
155
* Allocate an object in the exchange heap
156
156
*/
157
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);
158
+ extern " C" CDECL uintptr_t
159
+ exchange_malloc (rust_task *task, type_desc *td, uintptr_t size) {
167
160
168
- LOG (task, mem, " upcall exchange malloc(0x%" PRIxPTR " )" , args-> td );
161
+ LOG (task, mem, " upcall exchange malloc(0x%" PRIxPTR " )" , td);
169
162
170
163
// Copied from boxed_region
171
164
size_t header_size = sizeof (rust_opaque_box);
172
- size_t body_size = args-> td -> size ;
173
- size_t body_align = args-> td ->align ;
165
+ size_t body_size = size;
166
+ size_t body_align = td->align ;
174
167
size_t total_size = align_to (header_size, body_align) + body_size;
175
168
176
169
void *p = task->kernel ->malloc (total_size, " exchange malloc" );
177
170
memset (p, ' \0 ' , total_size);
178
171
179
172
rust_opaque_box *header = static_cast <rust_opaque_box*>(p);
180
- header->td = args->td ;
173
+ header->td = td;
174
+
175
+ return (uintptr_t )header;
176
+ }
177
+
178
+ struct s_exchange_malloc_args {
179
+ uintptr_t retval;
180
+ type_desc *td;
181
+ };
182
+
183
+ extern " C" CDECL void
184
+ upcall_s_exchange_malloc (s_exchange_malloc_args *args) {
185
+ rust_task *task = rust_get_current_task ();
186
+ LOG_UPCALL_ENTRY (task);
181
187
182
- args->retval = (uintptr_t )header;
188
+ uintptr_t retval = exchange_malloc (task, args->td , args->td ->size );
189
+ args->retval = retval;
183
190
}
184
191
185
192
extern " C" CDECL uintptr_t
@@ -189,6 +196,28 @@ upcall_exchange_malloc(type_desc *td) {
189
196
return args.retval ;
190
197
}
191
198
199
+ struct s_exchange_malloc_dyn_args {
200
+ uintptr_t retval;
201
+ type_desc *td;
202
+ uintptr_t size;
203
+ };
204
+
205
+ extern " C" CDECL void
206
+ upcall_s_exchange_malloc_dyn (s_exchange_malloc_dyn_args *args) {
207
+ rust_task *task = rust_get_current_task ();
208
+ LOG_UPCALL_ENTRY (task);
209
+
210
+ uintptr_t retval = exchange_malloc (task, args->td , args->size );
211
+ args->retval = retval;
212
+ }
213
+
214
+ extern " C" CDECL uintptr_t
215
+ upcall_exchange_malloc_dyn (type_desc *td, uintptr_t size) {
216
+ s_exchange_malloc_dyn_args args = {0 , td, size};
217
+ UPCALL_SWITCH_STACK (&args, upcall_s_exchange_malloc_dyn);
218
+ return args.retval ;
219
+ }
220
+
192
221
struct s_exchange_free_args {
193
222
void *ptr;
194
223
};
0 commit comments