(root)/
strace-6.5/
src/
fetch_struct_mmsghdr.c
       1  /*
       2   * Copyright (c) 2016-2021 Dmitry V. Levin <ldv@strace.io>
       3   * All rights reserved.
       4   *
       5   * SPDX-License-Identifier: LGPL-2.1-or-later
       6   */
       7  
       8  #include "defs.h"
       9  
      10  #include DEF_MPERS_TYPE(struct_mmsghdr)
      11  
      12  #include "msghdr.h"
      13  typedef struct mmsghdr struct_mmsghdr;
      14  
      15  #include MPERS_DEFS
      16  
      17  /*
      18   * On success, return the number of fetched bytes.
      19   * On error, return 0;
      20   *
      21   * This function cannot use umove_or_printaddr because
      22   * it is called by dumpio and therefore cannot print anything.
      23   */
      24  
      25  MPERS_PRINTER_DECL(int, fetch_struct_mmsghdr,
      26  		   struct tcb *const tcp, const kernel_ulong_t addr,
      27  		   void *const p)
      28  {
      29  	struct mmsghdr *p_native = p;
      30  	struct_mmsghdr v_compat;
      31  
      32  	if (sizeof(*p_native) == sizeof(v_compat))
      33  		return umove(tcp, addr, p_native) ? 0 : sizeof(*p_native);
      34  
      35  	if (umove(tcp, addr, &v_compat))
      36  		return 0;
      37  
      38  	p_native->msg_hdr.msg_name = (void *) (unsigned long)
      39  	 v_compat.msg_hdr.msg_name;
      40  
      41  	p_native->msg_hdr.msg_namelen =
      42  	 v_compat.msg_hdr.msg_namelen;
      43  
      44  	p_native->msg_hdr.msg_iov = (void *) (unsigned long)
      45  	 v_compat.msg_hdr.msg_iov;
      46  
      47  	p_native->msg_hdr.msg_iovlen =
      48  	 v_compat.msg_hdr.msg_iovlen;
      49  
      50  	p_native->msg_hdr.msg_control = (void *) (unsigned long)
      51  	 v_compat.msg_hdr.msg_control;
      52  
      53  	p_native->msg_hdr.msg_controllen =
      54  	 v_compat.msg_hdr.msg_controllen;
      55  
      56  	p_native->msg_hdr.msg_flags =
      57  	 v_compat.msg_hdr.msg_flags;
      58  
      59  	p_native->msg_len =
      60  	 v_compat.msg_len;
      61  
      62  	return sizeof(v_compat);
      63  }
      64  
      65  MPERS_PRINTER_DECL(unsigned int, sizeof_struct_mmsghdr, void)
      66  {
      67  	return sizeof(struct_mmsghdr);
      68  }