brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · bc6d072 Raw
54 lines · cpp
1//===-- Linux implementation of recvmsg -----------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/sys/socket/recvmsg.h"10 11#include <linux/net.h>   // For SYS_SOCKET socketcall number.12#include <sys/syscall.h> // For syscall numbers.13 14#include "hdr/types/ssize_t.h"15#include "hdr/types/struct_msghdr.h"16#include "src/__support/OSUtil/syscall.h" // For internal syscall function.17#include "src/__support/common.h"18#include "src/__support/libc_errno.h"19#include "src/__support/macros/sanitizer.h"20 21namespace LIBC_NAMESPACE_DECL {22 23LLVM_LIBC_FUNCTION(ssize_t, recvmsg, (int sockfd, msghdr *msg, int flags)) {24#ifdef SYS_recvmsg25  ssize_t ret =26      LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_recvmsg, sockfd, msg, flags);27#elif defined(SYS_socketcall)28  unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),29                                    reinterpret_cast<unsigned long>(msg),30                                    static_cast<unsigned long>(flags)};31  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(32      SYS_socketcall, SYS_RECVMSG, sockcall_args);33#else34#error "socket and socketcall syscalls unavailable for this platform."35#endif36  if (ret < 0) {37    libc_errno = static_cast<int>(-ret);38    return -1;39  }40 41  // Unpoison the msghdr, as well as all its components.42  MSAN_UNPOISON(msg, sizeof(msghdr));43  MSAN_UNPOISON(msg->msg_name, msg->msg_namelen);44 45  for (size_t i = 0; i < msg->msg_iovlen; ++i) {46    MSAN_UNPOISON(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);47  }48  MSAN_UNPOISON(msg->msg_control, msg->msg_controllen);49 50  return ret;51}52 53} // namespace LIBC_NAMESPACE_DECL54