* Copied from kern/kern_exec.c */
| 266 | * Copied from kern/kern_exec.c |
| 267 | */ |
| 268 | static int |
| 269 | linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) |
| 270 | { |
| 271 | int argc, envc, error; |
| 272 | char **vectp; |
| 273 | char *stringp; |
| 274 | uintptr_t destp, ustringp; |
| 275 | struct ps_strings *arginfo; |
| 276 | char canary[LINUX_AT_RANDOM_LEN]; |
| 277 | size_t execpath_len; |
| 278 | struct proc *p; |
| 279 | |
| 280 | /* Calculate string base and vector table pointers. */ |
| 281 | p = imgp->proc; |
| 282 | if (imgp->execpath != NULL && imgp->auxargs != NULL) |
| 283 | execpath_len = strlen(imgp->execpath) + 1; |
| 284 | else |
| 285 | execpath_len = 0; |
| 286 | arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; |
| 287 | destp = (uintptr_t)arginfo; |
| 288 | |
| 289 | /* Install LINUX_PLATFORM. */ |
| 290 | destp -= linux_szplatform; |
| 291 | destp = rounddown2(destp, sizeof(void *)); |
| 292 | error = copyout(linux_kplatform, (void *)destp, linux_szplatform); |
| 293 | if (error != 0) |
| 294 | return (error); |
| 295 | |
| 296 | if (execpath_len != 0) { |
| 297 | destp -= execpath_len; |
| 298 | destp = rounddown2(destp, sizeof(void *)); |
| 299 | imgp->execpathp = (void *)destp; |
| 300 | error = copyout(imgp->execpath, imgp->execpathp, execpath_len); |
| 301 | if (error != 0) |
| 302 | return (error); |
| 303 | } |
| 304 | |
| 305 | /* Prepare the canary for SSP. */ |
| 306 | arc4rand(canary, sizeof(canary), 0); |
| 307 | destp -= roundup(sizeof(canary), sizeof(void *)); |
| 308 | imgp->canary = (void *)destp; |
| 309 | error = copyout(canary, imgp->canary, sizeof(canary)); |
| 310 | if (error != 0) |
| 311 | return (error); |
| 312 | |
| 313 | /* Allocate room for the argument and environment strings. */ |
| 314 | destp -= ARG_MAX - imgp->args->stringspace; |
| 315 | destp = rounddown2(destp, sizeof(void *)); |
| 316 | ustringp = destp; |
| 317 | |
| 318 | if (imgp->auxargs) { |
| 319 | /* |
| 320 | * Allocate room on the stack for the ELF auxargs |
| 321 | * array. It has LINUX_AT_COUNT entries. |
| 322 | */ |
| 323 | destp -= LINUX_AT_COUNT * sizeof(Elf32_Auxinfo); |
| 324 | destp = rounddown2(destp, sizeof(void *)); |
| 325 | } |