* XXX copied from ia32_sysvec.c. */
| 732 | * XXX copied from ia32_sysvec.c. |
| 733 | */ |
| 734 | static int |
| 735 | linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) |
| 736 | { |
| 737 | int argc, envc, error; |
| 738 | u_int32_t *vectp; |
| 739 | char *stringp; |
| 740 | uintptr_t destp, ustringp; |
| 741 | struct linux32_ps_strings *arginfo; |
| 742 | char canary[LINUX_AT_RANDOM_LEN]; |
| 743 | size_t execpath_len; |
| 744 | |
| 745 | /* Calculate string base and vector table pointers. */ |
| 746 | if (imgp->execpath != NULL && imgp->auxargs != NULL) |
| 747 | execpath_len = strlen(imgp->execpath) + 1; |
| 748 | else |
| 749 | execpath_len = 0; |
| 750 | |
| 751 | arginfo = (struct linux32_ps_strings *)LINUX32_PS_STRINGS; |
| 752 | destp = (uintptr_t)arginfo; |
| 753 | |
| 754 | if (execpath_len != 0) { |
| 755 | destp -= execpath_len; |
| 756 | destp = rounddown2(destp, sizeof(uint32_t)); |
| 757 | imgp->execpathp = (void *)destp; |
| 758 | error = copyout(imgp->execpath, imgp->execpathp, execpath_len); |
| 759 | if (error != 0) |
| 760 | return (error); |
| 761 | } |
| 762 | |
| 763 | /* Prepare the canary for SSP. */ |
| 764 | arc4rand(canary, sizeof(canary), 0); |
| 765 | destp -= roundup(sizeof(canary), sizeof(uint32_t)); |
| 766 | imgp->canary = (void *)destp; |
| 767 | error = copyout(canary, imgp->canary, sizeof(canary)); |
| 768 | if (error != 0) |
| 769 | return (error); |
| 770 | |
| 771 | /* Allocate room for the argument and environment strings. */ |
| 772 | destp -= ARG_MAX - imgp->args->stringspace; |
| 773 | destp = rounddown2(destp, sizeof(uint32_t)); |
| 774 | ustringp = destp; |
| 775 | |
| 776 | if (imgp->auxargs) { |
| 777 | /* |
| 778 | * Allocate room on the stack for the ELF auxargs |
| 779 | * array. It has LINUX_AT_COUNT entries. |
| 780 | */ |
| 781 | destp -= LINUX_AT_COUNT * sizeof(Elf32_Auxinfo); |
| 782 | destp = rounddown2(destp, sizeof(uint32_t)); |
| 783 | } |
| 784 | |
| 785 | vectp = (uint32_t *)destp; |
| 786 | |
| 787 | /* |
| 788 | * Allocate room for the argv[] and env vectors including the |
| 789 | * terminating NULL pointers. |
| 790 | */ |
| 791 | vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; |