njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- File/socket-related libc stuff. pub_core_libcfile.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 10 | Copyright (C) 2000-2017 Julian Seward |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 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. |
| 17 | |
| 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. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_CORE_LIBCFILE_H |
| 32 | #define __PUB_CORE_LIBCFILE_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module contains all the libc code that relates to |
| 36 | // files and sockets: opening, reading, writing, etc. |
sewardj | 9a66bb9 | 2006-10-17 01:38:13 +0000 | [diff] [blame] | 37 | // To use, you must first include: pub_core_vki.h |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 38 | //-------------------------------------------------------------------- |
| 39 | |
| 40 | #include "pub_tool_libcfile.h" |
| 41 | |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 42 | /* Move an fd into the Valgrind-safe range */ |
njn | 327fe8a | 2005-06-12 02:49:35 +0000 | [diff] [blame] | 43 | extern Int VG_(safe_fd) ( Int oldfd ); |
njn | bb7af3f | 2009-05-22 07:08:12 +0000 | [diff] [blame] | 44 | extern Int VG_(fcntl) ( Int fd, Int cmd, Addr arg ); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 45 | |
njn | ae7359b | 2005-06-19 21:10:42 +0000 | [diff] [blame] | 46 | /* Convert an fd into a filename */ |
florian | 3130eab | 2014-11-14 19:25:08 +0000 | [diff] [blame] | 47 | extern Bool VG_(resolve_filename) ( Int fd, const HChar** buf ); |
njn | ae7359b | 2005-06-19 21:10:42 +0000 | [diff] [blame] | 48 | |
sewardj | ec61b65 | 2008-08-19 07:03:04 +0000 | [diff] [blame] | 49 | /* Return the size of a file, or -1 in case of error */ |
| 50 | extern Long VG_(fsize) ( Int fd ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 51 | |
tom | b7c2f9d | 2014-05-22 08:57:06 +0000 | [diff] [blame] | 52 | /* Lookup an extended attribute for a file */ |
florian | 518850b | 2014-10-22 22:25:30 +0000 | [diff] [blame] | 53 | extern SysRes VG_(getxattr) ( const HChar* file_name, const HChar* attr_name, |
| 54 | Addr attr_value, SizeT attr_value_len ); |
tom | b7c2f9d | 2014-05-22 08:57:06 +0000 | [diff] [blame] | 55 | |
njn | 7375061 | 2005-10-14 03:11:30 +0000 | [diff] [blame] | 56 | /* Is the file a directory? */ |
njn | 63e5e6e | 2009-05-20 04:22:42 +0000 | [diff] [blame] | 57 | extern Bool VG_(is_dir) ( const HChar* f ); |
njn | 7375061 | 2005-10-14 03:11:30 +0000 | [diff] [blame] | 58 | |
njn | e38e233 | 2005-06-18 04:13:54 +0000 | [diff] [blame] | 59 | /* Default destination port to be used in logging over a network, if |
| 60 | none specified. */ |
| 61 | #define VG_CLO_DEFAULT_LOGPORT 1500 |
| 62 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 63 | extern Int VG_(connect_via_socket)( const HChar* str ); |
njn | 60bd46d | 2009-05-21 23:52:52 +0000 | [diff] [blame] | 64 | |
tom | a4a4f41 | 2005-11-17 12:01:56 +0000 | [diff] [blame] | 65 | extern UInt VG_(htonl) ( UInt x ); |
| 66 | extern UInt VG_(ntohl) ( UInt x ); |
| 67 | extern UShort VG_(htons) ( UShort x ); |
| 68 | extern UShort VG_(ntohs) ( UShort x ); |
| 69 | |
njn | 0cd5d97 | 2009-05-22 02:00:27 +0000 | [diff] [blame] | 70 | extern Int VG_(socket) ( Int domain, Int type, Int protocol ); |
| 71 | |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 72 | extern Int VG_(write_socket)( Int sd, const void *msg, Int count ); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 73 | extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen ); |
| 74 | extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen ); |
njn | 60bd46d | 2009-05-21 23:52:52 +0000 | [diff] [blame] | 75 | extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, |
| 76 | void *optval, Int *optlen ); |
sewardj | 5d616df | 2013-07-02 08:07:15 +0000 | [diff] [blame] | 77 | extern Int VG_(setsockopt) ( Int sd, Int level, Int optname, |
| 78 | void *optval, Int optlen ); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 79 | |
njn | 63e5e6e | 2009-05-20 04:22:42 +0000 | [diff] [blame] | 80 | extern Int VG_(access) ( const HChar* path, Bool irusr, Bool iwusr, |
| 81 | Bool ixusr ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 82 | |
njn | 7375061 | 2005-10-14 03:11:30 +0000 | [diff] [blame] | 83 | /* Is the file executable? Returns: 0 = success, non-0 is failure */ |
sewardj | c74b3ba | 2007-11-17 21:11:57 +0000 | [diff] [blame] | 84 | extern Int VG_(check_executable)(/*OUT*/Bool* is_setuid, |
njn | 63e5e6e | 2009-05-20 04:22:42 +0000 | [diff] [blame] | 85 | const HChar* f, Bool allow_setuid); |
njn | 7375061 | 2005-10-14 03:11:30 +0000 | [diff] [blame] | 86 | |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 87 | /* DDD: Note this moves (or at least, is believed to move) the file |
| 88 | pointer on Linux but doesn't on Darwin. This inconsistency should |
| 89 | be fixed. (In other words, why isn't the Linux version implemented |
| 90 | in terms of pread()?) */ |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 91 | extern SysRes VG_(pread) ( Int fd, void* buf, Int count, OffT offset ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 92 | |
philippe | cc64826 | 2013-05-26 21:09:20 +0000 | [diff] [blame] | 93 | /* Size of fullname buffer needed for a call to VG_(mkstemp) with |
| 94 | part_of_name having the given part_of_name_len. */ |
| 95 | extern SizeT VG_(mkstemp_fullname_bufsz) ( SizeT part_of_name_len ); |
| 96 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 97 | /* Create and open (-rw------) a tmp file name incorporating said arg. |
florian | 87c8abb | 2014-11-09 16:15:23 +0000 | [diff] [blame] | 98 | Returns -1 on failure, else the fd of the file. The file name is |
| 99 | written to the memory pointed to be fullname. The number of bytes written |
philippe | d47676f | 2014-08-09 11:26:51 +0000 | [diff] [blame] | 100 | is equal to VG_(mkstemp_fullname_bufsz)(VG_(strlen)(part_of_name)). */ |
| 101 | extern Int VG_(mkstemp) ( const HChar* part_of_name, /*OUT*/HChar* fullname ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 102 | |
sewardj | 198f34f | 2007-07-09 23:13:07 +0000 | [diff] [blame] | 103 | /* Record the process' working directory at startup. Is intended to |
| 104 | be called exactly once, at startup, before the working directory |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame] | 105 | changes. The saved value can later be acquired by calling |
| 106 | VG_(get_startup_wd) (in pub_tool_libcfile.h). Note that might |
| 107 | return if the working directory couldn't be found. */ |
| 108 | extern void VG_(record_startup_wd) ( void ); |
sewardj | 198f34f | 2007-07-09 23:13:07 +0000 | [diff] [blame] | 109 | |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 110 | #endif // __PUB_CORE_LIBCFILE_H |
| 111 | |
| 112 | /*--------------------------------------------------------------------*/ |
| 113 | /*--- end ---*/ |
| 114 | /*--------------------------------------------------------------------*/ |