socket.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. int ocall_socket(int domain, int type, int protocol)
  10. {
  11. return socket(domain, type, protocol);
  12. }
  13. int ocall_getsockopt(int sockfd, int level, int optname, void *val_buf,
  14. unsigned int val_buf_size, void *len_buf)
  15. {
  16. return getsockopt(sockfd, level, optname, val_buf,
  17. (socklen_t *)len_buf);
  18. }
  19. ssize_t ocall_sendmsg(int sockfd, void *msg_buf,
  20. unsigned int msg_buf_size, int flags)
  21. {
  22. struct msghdr *msg = (struct msghdr *)msg_buf;
  23. int i;
  24. ssize_t ret;
  25. if (msg->msg_name != NULL)
  26. msg->msg_name = msg_buf + (unsigned)(uintptr_t)msg->msg_name;
  27. if (msg->msg_control != NULL)
  28. msg->msg_control = msg_buf + (unsigned)(uintptr_t)msg->msg_control;
  29. if (msg->msg_iov != NULL) {
  30. msg->msg_iov = msg_buf + (unsigned)(uintptr_t)msg->msg_iov;
  31. for (i = 0; i < msg->msg_iovlen; i++) {
  32. msg->msg_iov[i].iov_base = msg_buf + (unsigned)(uintptr_t)
  33. msg->msg_iov[i].iov_base;
  34. }
  35. }
  36. return sendmsg(sockfd, msg, flags);
  37. }
  38. ssize_t ocall_recvmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size,
  39. int flags)
  40. {
  41. struct msghdr *msg = (struct msghdr *)msg_buf;
  42. int i;
  43. ssize_t ret;
  44. if (msg->msg_name != NULL)
  45. msg->msg_name = msg_buf + (unsigned)(uintptr_t)msg->msg_name;
  46. if (msg->msg_control != NULL)
  47. msg->msg_control = msg_buf + (unsigned)(uintptr_t)msg->msg_control;
  48. if (msg->msg_iov != NULL) {
  49. msg->msg_iov = msg_buf + (unsigned)(uintptr_t)msg->msg_iov;
  50. for (i = 0; i <msg->msg_iovlen; i++) {
  51. msg->msg_iov[i].iov_base = msg_buf + (unsigned)(uintptr_t)
  52. msg->msg_iov[i].iov_base;
  53. }
  54. }
  55. return recvmsg(sockfd, msg, flags);
  56. }
  57. int ocall_shutdown(int sockfd, int how)
  58. {
  59. return shutdown(sockfd, how);
  60. }