2015-12-17 20:56:48 +03:00
/*
* Copyright ( c ) 2015 Dmitry V . Levin < ldv @ altlinux . org >
2017-05-22 20:14:52 +03:00
* Copyright ( c ) 2015 - 2017 The strace developers .
2015-12-17 20:56:48 +03:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2015-11-15 05:22:44 +03:00
# include "defs.h"
2017-07-19 00:54:38 +03:00
# include "print_fields.h"
2015-11-15 05:22:44 +03:00
# include <fcntl.h>
# include "xlat/uffd_flags.h"
SYS_FUNC ( userfaultfd )
{
printflags ( uffd_flags , tcp - > u_arg [ 0 ] , " UFFD_??? " ) ;
return RVAL_DECODED | RVAL_FD ;
}
2016-05-10 13:49:02 +03:00
# ifdef HAVE_LINUX_USERFAULTFD_H
# include <linux / ioctl.h>
# include <linux / userfaultfd.h>
2017-07-19 03:33:56 +03:00
# include "xlat / uffd_api_features.h"
2016-05-10 13:49:02 +03:00
# include "xlat / uffd_api_flags.h"
# include "xlat / uffd_copy_flags.h"
# include "xlat / uffd_register_ioctl_flags.h"
# include "xlat / uffd_register_mode_flags.h"
# include "xlat / uffd_zeropage_flags.h"
static void
tprintf_uffdio_range ( const struct uffdio_range * range )
{
2017-07-19 00:54:38 +03:00
PRINT_FIELD_X ( " { " , * range , start ) ;
PRINT_FIELD_X ( " , " , * range , len ) ;
tprints ( " } " ) ;
2016-05-10 13:49:02 +03:00
}
2017-07-19 00:54:38 +03:00
# define PRINT_FIELD_UFFDIO_RANGE(prefix_, where_, field_) \
do { \
STRACE_PRINTF ( " %s%s= " , ( prefix_ ) , # field_ ) ; \
tprintf_uffdio_range ( & ( where_ ) . field_ ) ; \
} while ( 0 )
2016-05-10 13:49:02 +03:00
int
Change type of ioctl 3rd argument from long to kernel_ureg_t
* defs.h (DECL_IOCTL): Change arg type from long to kernel_ureg_t.
* dm.c (dm_known_ioctl, dm_ioctl): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* fs_x_ioctl.c (fs_x_ioctl): Likewise.
* ioctl.c (ioctl_decode): Likewise.
* loop.c (decode_loop_info, decode_loop_info64): Change addr type
from long to kernel_ureg_t.
(loop_ioctl): Change arg type from long to kernel_ureg_t.
* ptp.c (ptp_ioctl): Likewise.
* scsi.c (print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res, scsi_ioctl): Likewise.
* sock.c (print_ifreq, sock_ioctl): Likewise.
(decode_ifconf): Change addr type from long to kernel_ureg_t.
* term.c (decode_termios, decode_termio, decode_winsize, decode_ttysize,
decode_modem_flags): Likewise.
(term_ioctl): Change arg type from long to kernel_ureg_t.
* ubi.c (ubi_ioctl): Likewise.
* userfaultfd.c (uffdio_ioctl): Likewise.
2016-12-21 06:03:09 +03:00
uffdio_ioctl ( struct tcb * const tcp , const unsigned int code ,
2016-12-26 13:26:03 +03:00
const kernel_ulong_t arg )
2016-05-10 13:49:02 +03:00
{
switch ( code ) {
case UFFDIO_API : {
2017-07-19 03:33:56 +03:00
uint64_t * entering_features ;
2016-05-10 13:49:02 +03:00
struct uffdio_api ua ;
2017-08-27 01:54:24 +03:00
2016-05-10 13:49:02 +03:00
if ( entering ( tcp ) ) {
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & ua ) )
2017-08-27 01:54:24 +03:00
break ;
2017-07-19 00:54:38 +03:00
PRINT_FIELD_X ( " { " , ua , api ) ;
2017-07-23 14:16:23 +03:00
PRINT_FIELD_FLAGS ( " , " , ua , features , uffd_api_features ,
" UFFD_FEATURE_??? " ) ;
2017-07-19 03:33:56 +03:00
entering_features = malloc ( sizeof ( * entering_features ) ) ;
if ( entering_features ) {
* entering_features = ua . features ;
set_tcb_priv_data ( tcp , entering_features , free ) ;
}
2017-08-27 01:54:24 +03:00
return 0 ;
}
if ( ! syserror ( tcp ) & & ! umove ( tcp , arg , & ua ) ) {
entering_features = get_tcb_priv_data ( tcp ) ;
if ( ! entering_features
| | * entering_features ! = ua . features ) {
PRINT_FIELD_FLAGS ( " => " , ua , features ,
uffd_api_features ,
" UFFD_FEATURE_??? " ) ;
2016-05-10 13:49:02 +03:00
}
2017-08-27 01:54:24 +03:00
PRINT_FIELD_FLAGS ( " , " , ua , ioctls , uffd_api_flags ,
" _UFFDIO_??? " ) ;
2016-05-10 13:49:02 +03:00
}
2017-08-27 01:54:24 +03:00
tprints ( " } " ) ;
break ;
2016-05-10 13:49:02 +03:00
}
case UFFDIO_COPY : {
struct uffdio_copy uc ;
2017-08-27 01:54:24 +03:00
2016-05-10 13:49:02 +03:00
if ( entering ( tcp ) ) {
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & uc ) )
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2017-07-19 00:54:38 +03:00
PRINT_FIELD_X ( " { " , uc , dst ) ;
PRINT_FIELD_X ( " , " , uc , src ) ;
PRINT_FIELD_X ( " , " , uc , len ) ;
2017-07-23 14:16:23 +03:00
PRINT_FIELD_FLAGS ( " , " , uc , mode , uffd_copy_flags ,
" UFFDIO_COPY_??? " ) ;
2017-08-27 01:54:24 +03:00
return 0 ;
2016-05-10 13:49:02 +03:00
}
2017-08-27 01:54:24 +03:00
if ( ! syserror ( tcp ) & & ! umove ( tcp , arg , & uc ) )
PRINT_FIELD_X ( " , " , uc , copy ) ;
tprints ( " } " ) ;
break ;
2016-05-10 13:49:02 +03:00
}
case UFFDIO_REGISTER : {
struct uffdio_register ur ;
2017-08-27 01:54:24 +03:00
2016-05-10 13:49:02 +03:00
if ( entering ( tcp ) ) {
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & ur ) )
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2017-07-19 00:54:38 +03:00
PRINT_FIELD_UFFDIO_RANGE ( " { " , ur , range ) ;
2017-07-23 14:16:23 +03:00
PRINT_FIELD_FLAGS ( " , " , ur , mode ,
uffd_register_mode_flags ,
" UFFDIO_REGISTER_MODE_??? " ) ;
2017-08-27 01:54:24 +03:00
return 0 ;
}
if ( ! syserror ( tcp ) & & ! umove ( tcp , arg , & ur ) ) {
PRINT_FIELD_FLAGS ( " , " , ur , ioctls ,
uffd_register_ioctl_flags ,
" UFFDIO_??? " ) ;
2016-05-10 13:49:02 +03:00
}
2017-08-27 01:54:24 +03:00
tprints ( " } " ) ;
break ;
2016-05-10 13:49:02 +03:00
}
case UFFDIO_UNREGISTER :
case UFFDIO_WAKE : {
struct uffdio_range ura ;
2017-08-27 01:54:24 +03:00
2016-05-10 13:49:02 +03:00
tprints ( " , " ) ;
2017-08-27 01:54:24 +03:00
2016-05-10 13:49:02 +03:00
if ( ! umove_or_printaddr ( tcp , arg , & ura ) )
tprintf_uffdio_range ( & ura ) ;
2017-08-27 01:54:24 +03:00
break ;
2016-05-10 13:49:02 +03:00
}
case UFFDIO_ZEROPAGE : {
struct uffdio_zeropage uz ;
2017-08-27 01:54:24 +03:00
2016-05-10 13:49:02 +03:00
if ( entering ( tcp ) ) {
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & uz ) )
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2017-07-19 00:54:38 +03:00
PRINT_FIELD_UFFDIO_RANGE ( " { " , uz , range ) ;
2017-07-23 14:16:23 +03:00
PRINT_FIELD_FLAGS ( " , " , uz , mode , uffd_zeropage_flags ,
" UFFDIO_ZEROPAGE_??? " ) ;
2017-08-27 01:54:24 +03:00
return 0 ;
2016-05-10 13:49:02 +03:00
}
2017-08-27 01:54:24 +03:00
if ( ! syserror ( tcp ) & & ! umove ( tcp , arg , & uz ) )
PRINT_FIELD_X ( " , " , uz , zeropage ) ;
tprints ( " } " ) ;
break ;
2016-05-10 13:49:02 +03:00
}
default :
return RVAL_DECODED ;
}
2017-08-27 01:54:24 +03:00
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2016-05-10 13:49:02 +03:00
}
# endif /* HAVE_LINUX_USERFAULTFD_H */