1*cf84ac9aSAndroid Build Coastguard Worker /*
2*cf84ac9aSAndroid Build Coastguard Worker * Copyright (c) 2015 Dmitry V. Levin <[email protected]>
3*cf84ac9aSAndroid Build Coastguard Worker * Copyright (c) 2015-2017 The strace developers.
4*cf84ac9aSAndroid Build Coastguard Worker * All rights reserved.
5*cf84ac9aSAndroid Build Coastguard Worker *
6*cf84ac9aSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
7*cf84ac9aSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions
8*cf84ac9aSAndroid Build Coastguard Worker * are met:
9*cf84ac9aSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright
10*cf84ac9aSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer.
11*cf84ac9aSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright
12*cf84ac9aSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the
13*cf84ac9aSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution.
14*cf84ac9aSAndroid Build Coastguard Worker * 3. The name of the author may not be used to endorse or promote products
15*cf84ac9aSAndroid Build Coastguard Worker * derived from this software without specific prior written permission.
16*cf84ac9aSAndroid Build Coastguard Worker *
17*cf84ac9aSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18*cf84ac9aSAndroid Build Coastguard Worker * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19*cf84ac9aSAndroid Build Coastguard Worker * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*cf84ac9aSAndroid Build Coastguard Worker * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21*cf84ac9aSAndroid Build Coastguard Worker * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22*cf84ac9aSAndroid Build Coastguard Worker * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23*cf84ac9aSAndroid Build Coastguard Worker * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24*cf84ac9aSAndroid Build Coastguard Worker * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25*cf84ac9aSAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26*cf84ac9aSAndroid Build Coastguard Worker * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*cf84ac9aSAndroid Build Coastguard Worker */
28*cf84ac9aSAndroid Build Coastguard Worker
29*cf84ac9aSAndroid Build Coastguard Worker #include "defs.h"
30*cf84ac9aSAndroid Build Coastguard Worker
31*cf84ac9aSAndroid Build Coastguard Worker #include DEF_MPERS_TYPE(struct_flock)
32*cf84ac9aSAndroid Build Coastguard Worker #include DEF_MPERS_TYPE(struct_flock64)
33*cf84ac9aSAndroid Build Coastguard Worker
34*cf84ac9aSAndroid Build Coastguard Worker #include "flock.h"
35*cf84ac9aSAndroid Build Coastguard Worker typedef struct_kernel_flock struct_flock;
36*cf84ac9aSAndroid Build Coastguard Worker typedef struct_kernel_flock64 struct_flock64;
37*cf84ac9aSAndroid Build Coastguard Worker
38*cf84ac9aSAndroid Build Coastguard Worker #include MPERS_DEFS
39*cf84ac9aSAndroid Build Coastguard Worker
40*cf84ac9aSAndroid Build Coastguard Worker #define SIZEOF_MEMBER(type, member) \
41*cf84ac9aSAndroid Build Coastguard Worker sizeof(((type *) NULL)->member)
42*cf84ac9aSAndroid Build Coastguard Worker
43*cf84ac9aSAndroid Build Coastguard Worker #define FLOCK_MEMBERS_EQ(type, member) \
44*cf84ac9aSAndroid Build Coastguard Worker (SIZEOF_MEMBER(struct_kernel_flock64, member) == SIZEOF_MEMBER(type, member) \
45*cf84ac9aSAndroid Build Coastguard Worker && offsetof(struct_kernel_flock64, member) == offsetof(type, member))
46*cf84ac9aSAndroid Build Coastguard Worker
47*cf84ac9aSAndroid Build Coastguard Worker #define FLOCK_STRUCTS_EQ(type) \
48*cf84ac9aSAndroid Build Coastguard Worker (sizeof(struct_kernel_flock64) == sizeof(type) \
49*cf84ac9aSAndroid Build Coastguard Worker && FLOCK_MEMBERS_EQ(type, l_type) \
50*cf84ac9aSAndroid Build Coastguard Worker && FLOCK_MEMBERS_EQ(type, l_whence) \
51*cf84ac9aSAndroid Build Coastguard Worker && FLOCK_MEMBERS_EQ(type, l_start) \
52*cf84ac9aSAndroid Build Coastguard Worker && FLOCK_MEMBERS_EQ(type, l_len) \
53*cf84ac9aSAndroid Build Coastguard Worker && FLOCK_MEMBERS_EQ(type, l_pid))
54*cf84ac9aSAndroid Build Coastguard Worker
MPERS_PRINTER_DECL(bool,fetch_struct_flock,struct tcb * const tcp,const kernel_ulong_t addr,void * const p)55*cf84ac9aSAndroid Build Coastguard Worker MPERS_PRINTER_DECL(bool, fetch_struct_flock, struct tcb *const tcp,
56*cf84ac9aSAndroid Build Coastguard Worker const kernel_ulong_t addr, void *const p)
57*cf84ac9aSAndroid Build Coastguard Worker {
58*cf84ac9aSAndroid Build Coastguard Worker struct_kernel_flock64 *pfl = p;
59*cf84ac9aSAndroid Build Coastguard Worker struct_flock mfl;
60*cf84ac9aSAndroid Build Coastguard Worker
61*cf84ac9aSAndroid Build Coastguard Worker if (FLOCK_STRUCTS_EQ(struct_flock))
62*cf84ac9aSAndroid Build Coastguard Worker return !umove_or_printaddr(tcp, addr, pfl);
63*cf84ac9aSAndroid Build Coastguard Worker
64*cf84ac9aSAndroid Build Coastguard Worker if (umove_or_printaddr(tcp, addr, &mfl))
65*cf84ac9aSAndroid Build Coastguard Worker return false;
66*cf84ac9aSAndroid Build Coastguard Worker
67*cf84ac9aSAndroid Build Coastguard Worker pfl->l_type = mfl.l_type;
68*cf84ac9aSAndroid Build Coastguard Worker pfl->l_whence = mfl.l_whence;
69*cf84ac9aSAndroid Build Coastguard Worker pfl->l_start = mfl.l_start;
70*cf84ac9aSAndroid Build Coastguard Worker pfl->l_len = mfl.l_len;
71*cf84ac9aSAndroid Build Coastguard Worker pfl->l_pid = mfl.l_pid;
72*cf84ac9aSAndroid Build Coastguard Worker return true;
73*cf84ac9aSAndroid Build Coastguard Worker }
74*cf84ac9aSAndroid Build Coastguard Worker
MPERS_PRINTER_DECL(bool,fetch_struct_flock64,struct tcb * const tcp,const kernel_ulong_t addr,void * const p)75*cf84ac9aSAndroid Build Coastguard Worker MPERS_PRINTER_DECL(bool, fetch_struct_flock64, struct tcb *const tcp,
76*cf84ac9aSAndroid Build Coastguard Worker const kernel_ulong_t addr, void *const p)
77*cf84ac9aSAndroid Build Coastguard Worker {
78*cf84ac9aSAndroid Build Coastguard Worker struct_kernel_flock64 *pfl = p;
79*cf84ac9aSAndroid Build Coastguard Worker struct_flock64 mfl;
80*cf84ac9aSAndroid Build Coastguard Worker
81*cf84ac9aSAndroid Build Coastguard Worker if (FLOCK_STRUCTS_EQ(struct_flock64))
82*cf84ac9aSAndroid Build Coastguard Worker return !umove_or_printaddr(tcp, addr, pfl);
83*cf84ac9aSAndroid Build Coastguard Worker
84*cf84ac9aSAndroid Build Coastguard Worker if (umove_or_printaddr(tcp, addr, &mfl))
85*cf84ac9aSAndroid Build Coastguard Worker return false;
86*cf84ac9aSAndroid Build Coastguard Worker
87*cf84ac9aSAndroid Build Coastguard Worker pfl->l_type = mfl.l_type;
88*cf84ac9aSAndroid Build Coastguard Worker pfl->l_whence = mfl.l_whence;
89*cf84ac9aSAndroid Build Coastguard Worker pfl->l_start = mfl.l_start;
90*cf84ac9aSAndroid Build Coastguard Worker pfl->l_len = mfl.l_len;
91*cf84ac9aSAndroid Build Coastguard Worker pfl->l_pid = mfl.l_pid;
92*cf84ac9aSAndroid Build Coastguard Worker return true;
93*cf84ac9aSAndroid Build Coastguard Worker }
94