bsd-mem.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * memory management system conversion routines
  3. *
  4. * Copyright (c) 2013 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. #include "qemu/osdep.h"
  20. #include "qemu.h"
  21. #include "qemu-bsd.h"
  22. struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS];
  23. abi_ulong target_brk;
  24. abi_ulong initial_target_brk;
  25. void target_set_brk(abi_ulong new_brk)
  26. {
  27. target_brk = TARGET_PAGE_ALIGN(new_brk);
  28. initial_target_brk = target_brk;
  29. }
  30. void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip,
  31. struct target_ipc_perm *target_ip)
  32. {
  33. __get_user(host_ip->cuid, &target_ip->cuid);
  34. __get_user(host_ip->cgid, &target_ip->cgid);
  35. __get_user(host_ip->uid, &target_ip->uid);
  36. __get_user(host_ip->gid, &target_ip->gid);
  37. __get_user(host_ip->mode, &target_ip->mode);
  38. __get_user(host_ip->seq, &target_ip->seq);
  39. __get_user(host_ip->key, &target_ip->key);
  40. }
  41. abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
  42. abi_ulong target_addr)
  43. {
  44. struct target_shmid_ds *target_sd;
  45. if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) {
  46. return -TARGET_EFAULT;
  47. }
  48. target_to_host_ipc_perm__locked(&(host_sd->shm_perm),
  49. &(target_sd->shm_perm));
  50. __get_user(host_sd->shm_segsz, &target_sd->shm_segsz);
  51. __get_user(host_sd->shm_lpid, &target_sd->shm_lpid);
  52. __get_user(host_sd->shm_cpid, &target_sd->shm_cpid);
  53. __get_user(host_sd->shm_nattch, &target_sd->shm_nattch);
  54. __get_user(host_sd->shm_atime, &target_sd->shm_atime);
  55. __get_user(host_sd->shm_dtime, &target_sd->shm_dtime);
  56. __get_user(host_sd->shm_ctime, &target_sd->shm_ctime);
  57. unlock_user_struct(target_sd, target_addr, 0);
  58. return 0;
  59. }
  60. void host_to_target_ipc_perm__locked(struct target_ipc_perm *target_ip,
  61. struct ipc_perm *host_ip)
  62. {
  63. __put_user(host_ip->cuid, &target_ip->cuid);
  64. __put_user(host_ip->cgid, &target_ip->cgid);
  65. __put_user(host_ip->uid, &target_ip->uid);
  66. __put_user(host_ip->gid, &target_ip->gid);
  67. __put_user(host_ip->mode, &target_ip->mode);
  68. __put_user(host_ip->seq, &target_ip->seq);
  69. __put_user(host_ip->key, &target_ip->key);
  70. }
  71. abi_long host_to_target_shmid_ds(abi_ulong target_addr,
  72. struct shmid_ds *host_sd)
  73. {
  74. struct target_shmid_ds *target_sd;
  75. if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
  76. return -TARGET_EFAULT;
  77. }
  78. host_to_target_ipc_perm__locked(&(target_sd->shm_perm),
  79. &(host_sd->shm_perm));
  80. __put_user(host_sd->shm_segsz, &target_sd->shm_segsz);
  81. __put_user(host_sd->shm_lpid, &target_sd->shm_lpid);
  82. __put_user(host_sd->shm_cpid, &target_sd->shm_cpid);
  83. __put_user(host_sd->shm_nattch, &target_sd->shm_nattch);
  84. __put_user(host_sd->shm_atime, &target_sd->shm_atime);
  85. __put_user(host_sd->shm_dtime, &target_sd->shm_dtime);
  86. __put_user(host_sd->shm_ctime, &target_sd->shm_ctime);
  87. unlock_user_struct(target_sd, target_addr, 1);
  88. return 0;
  89. }