(root)/
strace-6.5/
src/
fetch_struct_flock.c
       1  /*
       2   * Copyright (c) 2015 Dmitry V. Levin <ldv@strace.io>
       3   * Copyright (c) 2015-2021 The strace developers.
       4   * All rights reserved.
       5   *
       6   * SPDX-License-Identifier: LGPL-2.1-or-later
       7   */
       8  
       9  #include "defs.h"
      10  
      11  #include DEF_MPERS_TYPE(struct_flock)
      12  #include DEF_MPERS_TYPE(struct_flock64)
      13  
      14  #include <linux/fcntl.h>
      15  typedef struct flock struct_flock;
      16  typedef struct flock64 struct_flock64;
      17  
      18  #include MPERS_DEFS
      19  
      20  #define SIZEOF_MEMBER(type, member) \
      21  	sizeof(((type *) NULL)->member)
      22  
      23  #define FLOCK_MEMBERS_EQ(type, member) \
      24  	(SIZEOF_MEMBER(struct flock64, member) == SIZEOF_MEMBER(type, member) \
      25  	 && offsetof(struct flock64, member) == offsetof(type, member))
      26  
      27  #define FLOCK_STRUCTS_EQ(type) \
      28  	(sizeof(struct flock64) == sizeof(type) \
      29  	 && FLOCK_MEMBERS_EQ(type, l_type) \
      30  	 && FLOCK_MEMBERS_EQ(type, l_whence) \
      31  	 && FLOCK_MEMBERS_EQ(type, l_start) \
      32  	 && FLOCK_MEMBERS_EQ(type, l_len) \
      33  	 && FLOCK_MEMBERS_EQ(type, l_pid))
      34  
      35  MPERS_PRINTER_DECL(bool, fetch_struct_flock, struct tcb *const tcp,
      36  		   const kernel_ulong_t addr, void *const p)
      37  {
      38  	struct flock64 *pfl = p;
      39  	struct_flock mfl;
      40  
      41  	if (FLOCK_STRUCTS_EQ(struct_flock))
      42  		return !umove_or_printaddr(tcp, addr, pfl);
      43  
      44  	if (umove_or_printaddr(tcp, addr, &mfl))
      45  		return false;
      46  
      47  	pfl->l_type = mfl.l_type;
      48  	pfl->l_whence = mfl.l_whence;
      49  	pfl->l_start = mfl.l_start;
      50  	pfl->l_len = mfl.l_len;
      51  	pfl->l_pid = mfl.l_pid;
      52  	return true;
      53  }
      54  
      55  MPERS_PRINTER_DECL(bool, fetch_struct_flock64, struct tcb *const tcp,
      56  		   const kernel_ulong_t addr, void *const p)
      57  {
      58  	struct flock64 *pfl = p;
      59  	struct_flock64 mfl;
      60  
      61  	if (FLOCK_STRUCTS_EQ(struct_flock64))
      62  		return !umove_or_printaddr(tcp, addr, pfl);
      63  
      64  	if (umove_or_printaddr(tcp, addr, &mfl))
      65  		return false;
      66  
      67  	pfl->l_type = mfl.l_type;
      68  	pfl->l_whence = mfl.l_whence;
      69  	pfl->l_start = mfl.l_start;
      70  	pfl->l_len = mfl.l_len;
      71  	pfl->l_pid = mfl.l_pid;
      72  	return true;
      73  }