socket.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  10. ocall_socket(int domain, int type, int protocol)
  11. {
  12. return socket(domain, type, protocol);
  13. }
  14. int
  15. ocall_getsockopt(int sockfd, int level, int optname, void *val_buf,
  16. unsigned int val_buf_size, void *len_buf)
  17. {
  18. return getsockopt(sockfd, level, optname, val_buf, (socklen_t *)len_buf);
  19. }
  20. ssize_t
  21. ocall_sendmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size, int flags)
  22. {
  23. struct msghdr *msg = (struct msghdr *)msg_buf;
  24. int i;
  25. ssize_t ret;
  26. if (msg->msg_name != NULL)
  27. msg->msg_name = msg_buf + (unsigned)(uintptr_t)msg->msg_name;
  28. if (msg->msg_control != NULL)
  29. msg->msg_control = msg_buf + (unsigned)(uintptr_t)msg->msg_control;
  30. if (msg->msg_iov != NULL) {
  31. msg->msg_iov = msg_buf + (unsigned)(uintptr_t)msg->msg_iov;
  32. for (i = 0; i < msg->msg_iovlen; i++) {
  33. msg->msg_iov[i].iov_base =
  34. msg_buf + (unsigned)(uintptr_t)msg->msg_iov[i].iov_base;
  35. }
  36. }
  37. return sendmsg(sockfd, msg, flags);
  38. }
  39. ssize_t
  40. ocall_recvmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size, int flags)
  41. {
  42. struct msghdr *msg = (struct msghdr *)msg_buf;
  43. int i;
  44. ssize_t ret;
  45. if (msg->msg_name != NULL)
  46. msg->msg_name = msg_buf + (unsigned)(uintptr_t)msg->msg_name;
  47. if (msg->msg_control != NULL)
  48. msg->msg_control = msg_buf + (unsigned)(uintptr_t)msg->msg_control;
  49. if (msg->msg_iov != NULL) {
  50. msg->msg_iov = msg_buf + (unsigned)(uintptr_t)msg->msg_iov;
  51. for (i = 0; i < msg->msg_iovlen; i++) {
  52. msg->msg_iov[i].iov_base =
  53. msg_buf + (unsigned)(uintptr_t)msg->msg_iov[i].iov_base;
  54. }
  55. }
  56. return recvmsg(sockfd, msg, flags);
  57. }
  58. int
  59. ocall_shutdown(int sockfd, int how)
  60. {
  61. return shutdown(sockfd, how);
  62. }