2 /*--------------------------------------------------------------------*/
3 /*--- File/socket-related libc stuff. pub_core_libcfile.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Julian Seward
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_CORE_LIBCFILE_H
30 #define __PUB_CORE_LIBCFILE_H
32 //--------------------------------------------------------------------
33 // PURPOSE: This module contains all the libc code that relates to
34 // files and sockets: opening, reading, writing, etc.
35 // To use, you must first include: pub_core_vki.h
36 //--------------------------------------------------------------------
38 #include "pub_tool_libcfile.h"
40 /* Move an fd into the Valgrind-safe range */
41 extern Int
VG_(safe_fd
) ( Int oldfd
);
42 extern Int
VG_(fcntl
) ( Int fd
, Int cmd
, Addr arg
);
44 /* Convert an fd into a filename */
45 extern Bool
VG_(resolve_filename
) ( Int fd
, const HChar
** buf
);
47 #if defined(VGO_freebsd)
48 /* get the flags used to obtain an fd */
49 extern Bool
VG_(resolve_filemode
) ( Int fd
, Int
* result
);
52 /* Return the size of a file, or -1 in case of error */
53 extern Long
VG_(fsize
) ( Int fd
);
55 /* Lookup an extended attribute for a file */
56 extern SysRes
VG_(getxattr
) ( const HChar
* file_name
, const HChar
* attr_name
,
57 Addr attr_value
, SizeT attr_value_len
);
59 /* Is the file a directory? */
60 extern Bool
VG_(is_dir
) ( const HChar
* f
);
62 /* Default destination port to be used in logging over a network, if
64 #define VG_CLO_DEFAULT_LOGPORT 1500
66 extern Int
VG_(connect_via_socket
)( const HChar
* str
);
68 extern UInt
VG_(htonl
) ( UInt x
);
69 extern UInt
VG_(ntohl
) ( UInt x
);
70 extern UShort
VG_(htons
) ( UShort x
);
71 extern UShort
VG_(ntohs
) ( UShort x
);
73 extern Int
VG_(socket
) ( Int domain
, Int type
, Int protocol
);
75 extern Int
VG_(write_socket
)( Int sd
, const void *msg
, Int count
);
76 extern Int
VG_(getsockname
) ( Int sd
, struct vki_sockaddr
*name
, Int
*namelen
);
77 extern Int
VG_(getpeername
) ( Int sd
, struct vki_sockaddr
*name
, Int
*namelen
);
78 extern Int
VG_(getsockopt
) ( Int sd
, Int level
, Int optname
,
79 void *optval
, Int
*optlen
);
80 extern Int
VG_(setsockopt
) ( Int sd
, Int level
, Int optname
,
81 void *optval
, Int optlen
);
83 extern Int
VG_(access
) ( const HChar
* path
, Bool irusr
, Bool iwusr
,
86 /* Is the file executable? Returns: 0 = success, non-0 is failure */
87 extern Int
VG_(check_executable
)(/*OUT*/Bool
* is_setuid
,
88 const HChar
* f
, Bool allow_setuid
);
90 /* DDD: Note this moves (or at least, is believed to move) the file
91 pointer on Linux but doesn't on Darwin. This inconsistency should
92 be fixed. (In other words, why isn't the Linux version implemented
93 in terms of pread()?) */
94 extern SysRes
VG_(pread
) ( Int fd
, void* buf
, Int count
, OffT offset
);
96 /* Size of fullname buffer needed for a call to VG_(mkstemp) with
97 part_of_name having the given part_of_name_len. */
98 extern SizeT
VG_(mkstemp_fullname_bufsz
) ( SizeT part_of_name_len
);
100 /* Create and open (-rw------) a tmp file name incorporating said arg.
101 Returns -1 on failure, else the fd of the file. The file name is
102 written to the memory pointed to be fullname. The number of bytes written
103 is equal to VG_(mkstemp_fullname_bufsz)(VG_(strlen)(part_of_name)). */
104 extern Int
VG_(mkstemp
) ( const HChar
* part_of_name
, /*OUT*/HChar
* fullname
);
106 /* Record the process' working directory at startup. Is intended to
107 be called exactly once, at startup, before the working directory
108 changes. The saved value can later be acquired by calling
109 VG_(get_startup_wd) (in pub_tool_libcfile.h). Note that might
110 return if the working directory couldn't be found. */
111 extern void VG_(record_startup_wd
) ( void );
113 #endif // __PUB_CORE_LIBCFILE_H
115 /*--------------------------------------------------------------------*/
117 /*--------------------------------------------------------------------*/