2015-10-01 15:24:01 +03:00
/*
* Copyright ( c ) 1991 , 1992 Paul Kranenburg < pk @ cs . few . eur . nl >
* Copyright ( c ) 1993 Branko Lankester < branko @ hacktic . nl >
* Copyright ( c ) 1993 , 1994 , 1995 , 1996 Rick Sladkey < jrs @ world . std . com >
* Copyright ( c ) 1996 - 1999 Wichert Akkerman < wichert @ cistron . nl >
2018-06-14 14:00:00 +03:00
* Copyright ( c ) 1999 - 2018 The strace developers .
2015-10-01 15:24:01 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : LGPL - 2.1 - or - later
2015-10-01 15:24:01 +03:00
*/
# include "defs.h"
2015-10-09 04:38:07 +03:00
# include "flock.h"
2015-10-01 15:24:01 +03:00
fcntl.c: implement decoding for all known operations
* xlat/f_owner_types.in: New file.
* xlat/f_seals.in: Likewise.
* fcntl.c: Include "xlat/f_owner_types.h" and "xlat/f_seals.h".
(print_f_owner_ex): New function.
(SYS_FUNC(fcntl)): Use it.
Handle F_SETPIPE_SZ, F_GETPIPE_SZ, F_OFD_SETLKW,
F_OFD_SETLK, F_SETOWN_EX, F_ADD_SEALS, F_SETSIG,
F_OFD_GETLK, F_GETOWN_EX, F_GET_SEALS, F_GETSIG.
2015-10-10 00:08:43 +03:00
# include "xlat/f_owner_types.h"
# include "xlat/f_seals.h"
2015-10-01 15:24:01 +03:00
# include "xlat/fcntlcmds.h"
# include "xlat/fdflags.h"
# include "xlat/lockfcmds.h"
# include "xlat/notifyflags.h"
static void
2015-09-20 02:48:56 +03:00
print_struct_flock64 ( const struct_kernel_flock64 * fl , const int getlk )
{
tprints ( " {l_type= " ) ;
2016-05-17 00:57:08 +03:00
printxval ( lockfcmds , ( unsigned short ) fl - > l_type , " F_??? " ) ;
2015-09-20 02:48:56 +03:00
tprints ( " , l_whence= " ) ;
2016-05-17 00:57:08 +03:00
printxval ( whence_codes , ( unsigned short ) fl - > l_whence , " SEEK_??? " ) ;
2016-12-19 19:46:51 +03:00
tprintf ( " , l_start=% " PRId64 " , l_len=% " PRId64 ,
( int64_t ) fl - > l_start , ( int64_t ) fl - > l_len ) ;
2015-09-20 02:48:56 +03:00
if ( getlk )
tprintf ( " , l_pid=%lu " , ( unsigned long ) fl - > l_pid ) ;
tprints ( " } " ) ;
}
static void
2016-12-26 13:26:03 +03:00
printflock64 ( struct tcb * const tcp , const kernel_ulong_t addr , const int getlk )
2015-10-01 15:24:01 +03:00
{
2015-10-09 04:38:07 +03:00
struct_kernel_flock64 fl ;
2015-10-01 15:24:01 +03:00
2015-09-20 02:48:56 +03:00
if ( fetch_struct_flock64 ( tcp , addr , & fl ) )
print_struct_flock64 ( & fl , getlk ) ;
2015-10-01 15:24:01 +03:00
}
static void
2016-12-26 13:26:03 +03:00
printflock ( struct tcb * const tcp , const kernel_ulong_t addr , const int getlk )
2015-10-01 15:24:01 +03:00
{
2015-09-20 02:48:56 +03:00
struct_kernel_flock64 fl ;
2015-10-01 15:24:01 +03:00
2015-09-20 02:48:56 +03:00
if ( fetch_struct_flock ( tcp , addr , & fl ) )
print_struct_flock64 ( & fl , getlk ) ;
2015-10-01 15:24:01 +03:00
}
fcntl.c: implement decoding for all known operations
* xlat/f_owner_types.in: New file.
* xlat/f_seals.in: Likewise.
* fcntl.c: Include "xlat/f_owner_types.h" and "xlat/f_seals.h".
(print_f_owner_ex): New function.
(SYS_FUNC(fcntl)): Use it.
Handle F_SETPIPE_SZ, F_GETPIPE_SZ, F_OFD_SETLKW,
F_OFD_SETLK, F_SETOWN_EX, F_ADD_SEALS, F_SETSIG,
F_OFD_GETLK, F_GETOWN_EX, F_GET_SEALS, F_GETSIG.
2015-10-10 00:08:43 +03:00
static void
2016-12-26 13:26:03 +03:00
print_f_owner_ex ( struct tcb * const tcp , const kernel_ulong_t addr )
fcntl.c: implement decoding for all known operations
* xlat/f_owner_types.in: New file.
* xlat/f_seals.in: Likewise.
* fcntl.c: Include "xlat/f_owner_types.h" and "xlat/f_seals.h".
(print_f_owner_ex): New function.
(SYS_FUNC(fcntl)): Use it.
Handle F_SETPIPE_SZ, F_GETPIPE_SZ, F_OFD_SETLKW,
F_OFD_SETLK, F_SETOWN_EX, F_ADD_SEALS, F_SETSIG,
F_OFD_GETLK, F_GETOWN_EX, F_GET_SEALS, F_GETSIG.
2015-10-10 00:08:43 +03:00
{
struct { int type , pid ; } owner ;
if ( umove_or_printaddr ( tcp , addr , & owner ) )
return ;
tprints ( " {type= " ) ;
printxval ( f_owner_types , owner . type , " F_OWNER_??? " ) ;
tprintf ( " , pid=%d} " , owner . pid ) ;
}
2015-12-05 00:42:58 +03:00
static int
print_fcntl ( struct tcb * tcp )
2015-10-01 15:24:01 +03:00
{
2016-05-17 00:01:43 +03:00
const unsigned int cmd = tcp - > u_arg [ 1 ] ;
switch ( cmd ) {
2015-12-05 20:54:26 +03:00
case F_SETFD :
tprints ( " , " ) ;
printflags ( fdflags , tcp - > u_arg [ 2 ] , " FD_??? " ) ;
break ;
case F_SETOWN :
case F_SETPIPE_SZ :
2016-12-26 13:16:35 +03:00
tprintf ( " , % " PRI_kld , tcp - > u_arg [ 2 ] ) ;
2015-12-05 20:54:26 +03:00
break ;
case F_DUPFD :
case F_DUPFD_CLOEXEC :
2016-12-26 13:16:35 +03:00
tprintf ( " , % " PRI_kld , tcp - > u_arg [ 2 ] ) ;
2015-12-05 20:54:26 +03:00
return RVAL_DECODED | RVAL_FD ;
case F_SETFL :
tprints ( " , " ) ;
tprint_open_modes ( tcp - > u_arg [ 2 ] ) ;
break ;
case F_SETLK :
case F_SETLKW :
tprints ( " , " ) ;
printflock ( tcp , tcp - > u_arg [ 2 ] , 0 ) ;
break ;
case F_OFD_SETLK :
case F_OFD_SETLKW :
tprints ( " , " ) ;
printflock64 ( tcp , tcp - > u_arg [ 2 ] , 0 ) ;
break ;
case F_SETOWN_EX :
tprints ( " , " ) ;
print_f_owner_ex ( tcp , tcp - > u_arg [ 2 ] ) ;
break ;
case F_NOTIFY :
tprints ( " , " ) ;
2016-12-26 00:55:01 +03:00
printflags64 ( notifyflags , tcp - > u_arg [ 2 ] , " DN_??? " ) ;
2015-12-05 20:54:26 +03:00
break ;
case F_SETLEASE :
tprints ( " , " ) ;
2016-12-26 00:59:59 +03:00
printxval64 ( lockfcmds , tcp - > u_arg [ 2 ] , " F_??? " ) ;
2015-12-05 20:54:26 +03:00
break ;
case F_ADD_SEALS :
tprints ( " , " ) ;
2016-12-26 00:55:01 +03:00
printflags64 ( f_seals , tcp - > u_arg [ 2 ] , " F_SEAL_??? " ) ;
2015-12-05 20:54:26 +03:00
break ;
case F_SETSIG :
tprints ( " , " ) ;
tprints ( signame ( tcp - > u_arg [ 2 ] ) ) ;
break ;
case F_GETOWN :
case F_GETPIPE_SZ :
break ;
case F_GETFD :
if ( entering ( tcp ) | | syserror ( tcp ) | | tcp - > u_rval = = 0 )
return 0 ;
2016-05-15 17:23:06 +03:00
tcp - > auxstr = sprintflags ( " flags " , fdflags ,
2016-12-26 13:26:03 +03:00
( kernel_ulong_t ) tcp - > u_rval ) ;
2015-12-05 20:54:26 +03:00
return RVAL_HEX | RVAL_STR ;
case F_GETFL :
if ( entering ( tcp ) | | syserror ( tcp ) )
return 0 ;
tcp - > auxstr = sprint_open_modes ( tcp - > u_rval ) ;
return RVAL_HEX | RVAL_STR ;
case F_GETLK :
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printflock ( tcp , tcp - > u_arg [ 2 ] , 1 ) ;
break ;
case F_OFD_GETLK :
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printflock64 ( tcp , tcp - > u_arg [ 2 ] , 1 ) ;
break ;
case F_GETOWN_EX :
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
print_f_owner_ex ( tcp , tcp - > u_arg [ 2 ] ) ;
break ;
case F_GETLEASE :
if ( entering ( tcp ) | | syserror ( tcp ) )
return 0 ;
2016-12-26 13:26:03 +03:00
tcp - > auxstr = xlookup ( lockfcmds , ( kernel_ulong_t ) tcp - > u_rval ) ;
2015-12-05 20:54:26 +03:00
return RVAL_HEX | RVAL_STR ;
case F_GET_SEALS :
if ( entering ( tcp ) | | syserror ( tcp ) | | tcp - > u_rval = = 0 )
return 0 ;
2016-05-15 17:23:06 +03:00
tcp - > auxstr = sprintflags ( " seals " , f_seals ,
2016-12-26 13:26:03 +03:00
( kernel_ulong_t ) tcp - > u_rval ) ;
2015-12-05 20:54:26 +03:00
return RVAL_HEX | RVAL_STR ;
case F_GETSIG :
if ( entering ( tcp ) | | syserror ( tcp ) | | tcp - > u_rval = = 0 )
2015-10-09 04:55:46 +03:00
return 0 ;
2015-12-05 20:54:26 +03:00
tcp - > auxstr = signame ( tcp - > u_rval ) ;
return RVAL_STR ;
default :
2016-12-26 13:16:35 +03:00
tprintf ( " , %# " PRI_klx , tcp - > u_arg [ 2 ] ) ;
2015-12-05 20:54:26 +03:00
break ;
2015-10-01 15:24:01 +03:00
}
2015-12-05 20:54:26 +03:00
return RVAL_DECODED ;
2015-10-01 15:24:01 +03:00
}
2015-12-05 00:42:58 +03:00
SYS_FUNC ( fcntl )
{
fcntl: skip F_GETLK64, F_SETLK64, and F_SETLKW64 in fcntl syscall parser
As the kernel recognizes F_GETLK64, F_SETLK64, and F_SETLKW64 commands
in fcntl64 syscall only, do not parse their structures in fcntl parser.
* xlat/fcntlcmds.in: Move F_GETLK64, F_SETLK64, and F_SETLKW64 ...
* xlat/fcntl64cmds.in: ... here.
* fcntl.c: Include "xlat/fcntl64cmds.h".
(print_fcntl): Move printing of first two syscall arguments
and handling of F_GETLK64, F_SETLK64, and F_SETLKW64 commands ...
(SYS_FUNC(fcntl), SYS_FUNC(fcntl64)): ... here.
* tests/fcntl.c: New file, based on struct_flock.c.
* tests/fcntl64.c: Likewise.
* tests/struct_flock.c (test_flock_einval, create_sample): New functions.
(test_flock): Use test_flock_einval.
(test_flock64, main): Remove.
* tests/fcntl.test: New test.
* tests/fcntl64.test: Likewise.
* tests/struct_flock.test: Remove.
* tests/Makefile.am (check_PROGRAMS): Add fcntl and fcntl64,
remove struct_flock.
(TESTS): Add fcntl.test and fcntl64.test, remove struct_flock.test.
(EXTRA_DIST) Add struct_flock.c.
* tests/.gitignore: Add fcntl and fcntl64, remove struct_flock.
2015-12-05 03:52:01 +03:00
if ( entering ( tcp ) ) {
printfd ( tcp , tcp - > u_arg [ 0 ] ) ;
tprints ( " , " ) ;
2018-05-02 18:23:46 +03:00
printxval ( fcntlcmds , tcp - > u_arg [ 1 ] , " F_??? " ) ;
fcntl: skip F_GETLK64, F_SETLK64, and F_SETLKW64 in fcntl syscall parser
As the kernel recognizes F_GETLK64, F_SETLK64, and F_SETLKW64 commands
in fcntl64 syscall only, do not parse their structures in fcntl parser.
* xlat/fcntlcmds.in: Move F_GETLK64, F_SETLK64, and F_SETLKW64 ...
* xlat/fcntl64cmds.in: ... here.
* fcntl.c: Include "xlat/fcntl64cmds.h".
(print_fcntl): Move printing of first two syscall arguments
and handling of F_GETLK64, F_SETLK64, and F_SETLKW64 commands ...
(SYS_FUNC(fcntl), SYS_FUNC(fcntl64)): ... here.
* tests/fcntl.c: New file, based on struct_flock.c.
* tests/fcntl64.c: Likewise.
* tests/struct_flock.c (test_flock_einval, create_sample): New functions.
(test_flock): Use test_flock_einval.
(test_flock64, main): Remove.
* tests/fcntl.test: New test.
* tests/fcntl64.test: Likewise.
* tests/struct_flock.test: Remove.
* tests/Makefile.am (check_PROGRAMS): Add fcntl and fcntl64,
remove struct_flock.
(TESTS): Add fcntl.test and fcntl64.test, remove struct_flock.test.
(EXTRA_DIST) Add struct_flock.c.
* tests/.gitignore: Add fcntl and fcntl64, remove struct_flock.
2015-12-05 03:52:01 +03:00
}
2015-12-05 00:42:58 +03:00
return print_fcntl ( tcp ) ;
}
SYS_FUNC ( fcntl64 )
{
2016-05-17 00:01:43 +03:00
const unsigned int cmd = tcp - > u_arg [ 1 ] ;
fcntl: skip F_GETLK64, F_SETLK64, and F_SETLKW64 in fcntl syscall parser
As the kernel recognizes F_GETLK64, F_SETLK64, and F_SETLKW64 commands
in fcntl64 syscall only, do not parse their structures in fcntl parser.
* xlat/fcntlcmds.in: Move F_GETLK64, F_SETLK64, and F_SETLKW64 ...
* xlat/fcntl64cmds.in: ... here.
* fcntl.c: Include "xlat/fcntl64cmds.h".
(print_fcntl): Move printing of first two syscall arguments
and handling of F_GETLK64, F_SETLK64, and F_SETLKW64 commands ...
(SYS_FUNC(fcntl), SYS_FUNC(fcntl64)): ... here.
* tests/fcntl.c: New file, based on struct_flock.c.
* tests/fcntl64.c: Likewise.
* tests/struct_flock.c (test_flock_einval, create_sample): New functions.
(test_flock): Use test_flock_einval.
(test_flock64, main): Remove.
* tests/fcntl.test: New test.
* tests/fcntl64.test: Likewise.
* tests/struct_flock.test: Remove.
* tests/Makefile.am (check_PROGRAMS): Add fcntl and fcntl64,
remove struct_flock.
(TESTS): Add fcntl.test and fcntl64.test, remove struct_flock.test.
(EXTRA_DIST) Add struct_flock.c.
* tests/.gitignore: Add fcntl and fcntl64, remove struct_flock.
2015-12-05 03:52:01 +03:00
if ( entering ( tcp ) ) {
printfd ( tcp , tcp - > u_arg [ 0 ] ) ;
tprints ( " , " ) ;
2018-05-02 18:23:46 +03:00
printxval ( fcntlcmds , cmd , " F_??? " ) ;
fcntl: skip F_GETLK64, F_SETLK64, and F_SETLKW64 in fcntl syscall parser
As the kernel recognizes F_GETLK64, F_SETLK64, and F_SETLKW64 commands
in fcntl64 syscall only, do not parse their structures in fcntl parser.
* xlat/fcntlcmds.in: Move F_GETLK64, F_SETLK64, and F_SETLKW64 ...
* xlat/fcntl64cmds.in: ... here.
* fcntl.c: Include "xlat/fcntl64cmds.h".
(print_fcntl): Move printing of first two syscall arguments
and handling of F_GETLK64, F_SETLK64, and F_SETLKW64 commands ...
(SYS_FUNC(fcntl), SYS_FUNC(fcntl64)): ... here.
* tests/fcntl.c: New file, based on struct_flock.c.
* tests/fcntl64.c: Likewise.
* tests/struct_flock.c (test_flock_einval, create_sample): New functions.
(test_flock): Use test_flock_einval.
(test_flock64, main): Remove.
* tests/fcntl.test: New test.
* tests/fcntl64.test: Likewise.
* tests/struct_flock.test: Remove.
* tests/Makefile.am (check_PROGRAMS): Add fcntl and fcntl64,
remove struct_flock.
(TESTS): Add fcntl.test and fcntl64.test, remove struct_flock.test.
(EXTRA_DIST) Add struct_flock.c.
* tests/.gitignore: Add fcntl and fcntl64, remove struct_flock.
2015-12-05 03:52:01 +03:00
}
2016-05-17 00:01:43 +03:00
switch ( cmd ) {
fcntl: skip F_GETLK64, F_SETLK64, and F_SETLKW64 in fcntl syscall parser
As the kernel recognizes F_GETLK64, F_SETLK64, and F_SETLKW64 commands
in fcntl64 syscall only, do not parse their structures in fcntl parser.
* xlat/fcntlcmds.in: Move F_GETLK64, F_SETLK64, and F_SETLKW64 ...
* xlat/fcntl64cmds.in: ... here.
* fcntl.c: Include "xlat/fcntl64cmds.h".
(print_fcntl): Move printing of first two syscall arguments
and handling of F_GETLK64, F_SETLK64, and F_SETLKW64 commands ...
(SYS_FUNC(fcntl), SYS_FUNC(fcntl64)): ... here.
* tests/fcntl.c: New file, based on struct_flock.c.
* tests/fcntl64.c: Likewise.
* tests/struct_flock.c (test_flock_einval, create_sample): New functions.
(test_flock): Use test_flock_einval.
(test_flock64, main): Remove.
* tests/fcntl.test: New test.
* tests/fcntl64.test: Likewise.
* tests/struct_flock.test: Remove.
* tests/Makefile.am (check_PROGRAMS): Add fcntl and fcntl64,
remove struct_flock.
(TESTS): Add fcntl.test and fcntl64.test, remove struct_flock.test.
(EXTRA_DIST) Add struct_flock.c.
* tests/.gitignore: Add fcntl and fcntl64, remove struct_flock.
2015-12-05 03:52:01 +03:00
case F_SETLK64 :
case F_SETLKW64 :
tprints ( " , " ) ;
printflock64 ( tcp , tcp - > u_arg [ 2 ] , 0 ) ;
return RVAL_DECODED ;
case F_GETLK64 :
if ( exiting ( tcp ) ) {
tprints ( " , " ) ;
printflock64 ( tcp , tcp - > u_arg [ 2 ] , 1 ) ;
}
return 0 ;
}
2015-12-05 00:42:58 +03:00
return print_fcntl ( tcp ) ;
}