io-write.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <gnu/syscall.h>
  21. struct mach_msg_pointer_loff
  22. {
  23. mach_msg_header_t header;
  24. mach_msg_type_long_t type_one; char *one;
  25. mach_msg_type_t type_two; loff_t two;
  26. };
  27. kern_return_t
  28. __io_write (io_t io, data_t data, mach_msg_type_number_t size, loff_t offset, vm_size_t *wrote)
  29. {
  30. struct mach_msg_pointer_loff message = {0};
  31. message.header.msgh_size = sizeof (struct mach_msg_pointer_loff);
  32. message.type_one = mach_msg_type_pointer;
  33. message.one = data;
  34. message.type_two = mach_msg_type_int64;
  35. message.two = offset;
  36. message.type_one.msgtl_number = size;
  37. message.type_one.msgtl_header.msgt_inline = 0;
  38. message.header.msgh_bits = MACH_MSGH_BITS_COMPLEX;
  39. kern_return_t result = __syscall_put (io, SYS__io_write,
  40. &message.header,
  41. sizeof (struct mach_msg_2));
  42. if (result == KERN_SUCCESS)
  43. *wrote = message.two;
  44. return result;
  45. }