target_os_stack.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * OpenBSD setup_initial_stack() implementation.
  3. *
  4. * Copyright (c) 2013-14 Stacey D. Son
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef TARGET_OS_STACK_H
  20. #define TARGET_OS_STACK_H
  21. #include "target_arch_sigtramp.h"
  22. static inline int setup_initial_stack(struct bsd_binprm *bprm, abi_ulong *p,
  23. abi_ulong *stringp)
  24. {
  25. int i;
  26. abi_ulong stack_base;
  27. stack_base = (target_stkbas + target_stksiz) -
  28. MAX_ARG_PAGES * TARGET_PAGE_SIZE;
  29. if (p) {
  30. *p = stack_base;
  31. }
  32. if (stringp) {
  33. *stringp = stack_base;
  34. }
  35. for (i = 0; i < MAX_ARG_PAGES; i++) {
  36. if (bprm->page[i]) {
  37. info->rss++;
  38. if (!memcpy_to_target(stack_base, bprm->page[i],
  39. TARGET_PAGE_SIZE)) {
  40. errno = EFAULT;
  41. return -1;
  42. }
  43. g_free(bprm->page[i]);
  44. }
  45. stack_base += TARGET_PAGE_SIZE;
  46. }
  47. return 0;
  48. }
  49. #endif /* TARGET_OS_STACK_H */