# HG changeset patch # User Paul Boddie # Date 1677949211 -3600 # Node ID a86fe04c6e2e756e719eb09922828b649198a9fe # Parent 406b46fcc62fbabd68e065c32bc1b837c482ad1c Allocate payload and stack resources dynamically to permit control over when such resources may be released. diff -r 406b46fcc62f -r a86fe04c6e2e libexec/include/exec/process_creating.h --- a/libexec/include/exec/process_creating.h Sat Mar 04 12:42:09 2023 +0100 +++ b/libexec/include/exec/process_creating.h Sat Mar 04 18:00:11 2023 +0100 @@ -46,10 +46,10 @@ /* Stack and payload descriptions. */ - ExplicitSegment _rm_stack; + ExplicitSegment *_rm_stack = NULL; Payload *_rm_payload = NULL; - ExplicitSegment _program_stack; + ExplicitSegment *_program_stack = NULL; Payload *_program_payload = NULL; /* IPC gate for communication within the created task, plus allocated diff -r 406b46fcc62f -r a86fe04c6e2e libexec/lib/src/process_creating.cc --- a/libexec/lib/src/process_creating.cc Sat Mar 04 12:42:09 2023 +0100 +++ b/libexec/lib/src/process_creating.cc Sat Mar 04 18:00:11 2023 +0100 @@ -40,10 +40,10 @@ /* Initialise the process creator with the details of a region mapper. */ ProcessCreating::ProcessCreating(const char *rm_filename) -: _rm_filename(rm_filename), - _rm_stack(Utcb_area_start - initial_stack_size, initial_stack_size, L4_FPAGE_RW), - _program_stack(Utcb_area_start - initial_stack_size * 2, initial_stack_size, L4_FPAGE_RW) +: _rm_filename(rm_filename) { + _rm_stack = new ExplicitSegment(Utcb_area_start - initial_stack_size, initial_stack_size, L4_FPAGE_RW); + _program_stack = new ExplicitSegment(Utcb_area_start - initial_stack_size * 2, initial_stack_size, L4_FPAGE_RW); } /* Initialise the memory segments of the region mapper. These are mapped into @@ -57,7 +57,7 @@ if (err) return err; - return _rm_stack.allocate(true); + return _rm_stack->allocate(true); } /* Initialise the memory segments of the actual program. These are not mapped @@ -71,7 +71,7 @@ if (err) return err; - return _program_stack.allocate(true); + return _program_stack->allocate(true); } /* Initialise an external system-level pager serving the region mapper in a @@ -93,7 +93,7 @@ /* Include the region mapper's stack region. */ - _exec_pager->add(_rm_stack.region()); + _exec_pager->add(_rm_stack->region()); /* Start the pager in a separate thread. */ @@ -181,7 +181,7 @@ /* Introduce the stack region and capability. */ - init_region(rm_regions, rm_mapped_caps, _program_stack.exec_region(), rm_index); + init_region(rm_regions, rm_mapped_caps, _program_stack->exec_region(), rm_index); /* Terminate the region array. */ @@ -221,7 +221,7 @@ region mapper, plus the initial server capability and region details. */ const char *argv[] = {_rm_filename}; - Stack rm_st(_rm_stack); + Stack rm_st(*_rm_stack); rm_st.set_init_caps(rm_init_caps); rm_st.set_regions(rm_regions); @@ -260,7 +260,7 @@ actual program. The server capability should be assigned to the region mapper capability slot already. */ - Stack program_st(_program_stack); + Stack program_st(*_program_stack); program_st.populate(argc, argv, envp); @@ -318,12 +318,15 @@ _exec_pager->set_task(_process.get_task()); _exec_pager->set_gate(_ipc_gate); - /* Discard instances created to initialise the process. + /* Discard instances created to initialise the process. The region mapper + relies on resources associated with its payload and stack and so these + cannot be deleted immediately. + NOTE: The region mapper payload could be retained instead of being reconstructed each time. */ - delete _rm_payload; delete _program_payload; + delete _program_stack; return L4_EOK; }