1534217f7SWarner Losh /* 2534217f7SWarner Losh * OpenBSD setup_initial_stack() implementation. 3534217f7SWarner Losh * 4534217f7SWarner Losh * Copyright (c) 2013-14 Stacey D. Son 5534217f7SWarner Losh * 6534217f7SWarner Losh * This program is free software; you can redistribute it and/or modify 7534217f7SWarner Losh * it under the terms of the GNU General Public License as published by 8534217f7SWarner Losh * the Free Software Foundation; either version 2 of the License, or 9534217f7SWarner Losh * (at your option) any later version. 10534217f7SWarner Losh * 11534217f7SWarner Losh * This program is distributed in the hope that it will be useful, 12534217f7SWarner Losh * but WITHOUT ANY WARRANTY; without even the implied warranty of 13534217f7SWarner Losh * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14534217f7SWarner Losh * GNU General Public License for more details. 15534217f7SWarner Losh * 16534217f7SWarner Losh * You should have received a copy of the GNU General Public License 17534217f7SWarner Losh * along with this program; if not, see <http://www.gnu.org/licenses/>. 18534217f7SWarner Losh */ 19534217f7SWarner Losh 20*9c092804SMarkus Armbruster #ifndef TARGET_OS_STACK_H 21*9c092804SMarkus Armbruster #define TARGET_OS_STACK_H 22534217f7SWarner Losh 23534217f7SWarner Losh #include "target_arch_sigtramp.h" 24534217f7SWarner Losh setup_initial_stack(struct bsd_binprm * bprm,abi_ulong * p,abi_ulong * stringp)25534217f7SWarner Loshstatic inline int setup_initial_stack(struct bsd_binprm *bprm, abi_ulong *p, 26534217f7SWarner Losh abi_ulong *stringp) 27534217f7SWarner Losh { 28534217f7SWarner Losh int i; 29534217f7SWarner Losh abi_ulong stack_base; 30534217f7SWarner Losh 31534217f7SWarner Losh stack_base = (target_stkbas + target_stksiz) - 32534217f7SWarner Losh MAX_ARG_PAGES * TARGET_PAGE_SIZE; 33534217f7SWarner Losh if (p) { 34534217f7SWarner Losh *p = stack_base; 35534217f7SWarner Losh } 36534217f7SWarner Losh if (stringp) { 37534217f7SWarner Losh *stringp = stack_base; 38534217f7SWarner Losh } 39534217f7SWarner Losh 40534217f7SWarner Losh for (i = 0; i < MAX_ARG_PAGES; i++) { 41534217f7SWarner Losh if (bprm->page[i]) { 42534217f7SWarner Losh info->rss++; 43534217f7SWarner Losh if (!memcpy_to_target(stack_base, bprm->page[i], 44534217f7SWarner Losh TARGET_PAGE_SIZE)) { 45534217f7SWarner Losh errno = EFAULT; 46534217f7SWarner Losh return -1; 47534217f7SWarner Losh } 48534217f7SWarner Losh g_free(bprm->page[i]); 49534217f7SWarner Losh } 50534217f7SWarner Losh stack_base += TARGET_PAGE_SIZE; 51534217f7SWarner Losh } 52534217f7SWarner Losh 53534217f7SWarner Losh return 0; 54534217f7SWarner Losh } 55534217f7SWarner Losh 56*9c092804SMarkus Armbruster #endif /* TARGET_OS_STACK_H */ 57