diff options
author | Javier <dev.git@javispedro.com> | 2022-04-16 19:55:32 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2022-04-16 19:55:32 +0200 |
commit | 9cf5dd38521565ff889dc6b07187742ac67a7454 (patch) | |
tree | 7d20fdde1a00796047ffeca56a17677ef4883d73 /dostsr.h | |
parent | 1075670224d66edba07aa5c100917f3ace7d628c (diff) | |
download | vbados-9cf5dd38521565ff889dc6b07187742ac67a7454.tar.gz vbados-9cf5dd38521565ff889dc6b07187742ac67a7454.zip |
avoid leaking HMA on install error
Diffstat (limited to 'dostsr.h')
-rw-r--r-- | dostsr.h | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -96,9 +96,6 @@ static __segment reallocate_to_umb(segment_t cur_seg, unsigned segment_size) // Create a new program instance including PSP at the new_segment copy_program(new_segment_psp, old_segment_psp, segment_size); - // Tell DOS to "switch" to the new program - dos_set_psp(new_segment_psp); - // Return the new segment return new_segment; } else { @@ -111,4 +108,28 @@ static __segment reallocate_to_umb(segment_t cur_seg, unsigned segment_size) } } +/** Called in case there is an error and we should free our HMA segment. */ +static void cancel_reallocation(segment_t new_seg) +{ + segment_t new_segment_psp = new_seg - (DOS_PSP_SIZE/16); + dos_free(new_segment_psp); +} + +/** Called right before doing the TSR call. + * Frees the old code segment. */ +static void finish_reallocation(segment_t old_segment_psp, segment_t new_seg) +{ + segment_t new_segment_psp = new_seg - (DOS_PSP_SIZE/16); + + // Tell DOS that we are "switching" to the new program in the HMA + dos_set_psp(new_segment_psp); + + // We are about to free() the old code segment, + // which is likely where the currently running function code resides. + dos_free(old_segment_psp); + + // Nothing should try to allocate memory between this and the actual TSR call, + // since it could overwrite the currently running code... ! +} + #endif // DOSTSR_H |