Hello,
Maximus Minter, le mar. 07 avril 2026 22:30:33 -0400, a ecrit:
> - Replace alloca with kalloc in elf-load.c
>
> diff --git a/kern/elf-load.c b/kern/elf-load.c
> index 596233a8..c913778a 100644
> --- a/kern/elf-load.c
> +++ b/kern/elf-load.c
> @@ -22,7 +22,7 @@
> * OSF Research Institute MK6.1 (unencumbered) 1/31/1995
> */
>
> -#include <alloca.h>
> +#include <kern/kalloc.h>
> #include <mach/machine/vm_types.h>
> #include <mach/exec/elf.h>
> #include <mach/exec/exec.h>
> @@ -65,13 +65,19 @@ int exec_load(exec_read_func_t *read,
> exec_read_exec_func_t *read_exec,
> out_info->entry = (vm_offset_t) x.e_entry + loadbase;
>
> phsize = x.e_phnum * x.e_phentsize;
> - phdr = (Elf_Phdr *)alloca(phsize);
> + phdr = (Elf_Phdr *) kalloc(phsize);
> + if (phdr == NULL)
> + return KERN_RESOURCE_SHORTAGE;
>
> result = (*read)(handle, x.e_phoff, phdr, phsize, &actual);
> - if (result)
> + if (result) {
> + kfree((vm_offset_t)phdr, phsize);
> return result;
> - if (actual < phsize)
> + }
> + if (actual < phsize) {
> + kfree((vm_offset_t)phdr, phsize);
> return EX_CORRUPT;
> + }
>
> out_info->stack_prot = VM_PROT_ALL;
>
> @@ -89,8 +95,10 @@ int exec_load(exec_read_func_t *read,
> exec_read_exec_func_t *read_exec,
> result = (*read_exec)(handle,
> ph->p_offset, ph->p_filesz,
> ph->p_vaddr + loadbase,
> ph->p_memsz, type);
> - if (result)
> + if (result) {
> + kfree((vm_offset_t)phdr, phsize);
> return result;
> + }
> } else if (ph->p_type == PT_GNU_STACK) {
> out_info->stack_prot = 0;
> if (ph->p_flags & PF_R) out_info->stack_prot |=
> VM_PROT_READ;
> @@ -99,6 +107,7 @@ int exec_load(exec_read_func_t *read,
> exec_read_exec_func_t *read_exec,
> }
> }
>
> + if (phdr)
> + kfree((vm_offset_t)phdr, phsize);
> return 0;
> -}
Why doing that?
Samuel