30 #include "filenames.h"
36 #include <sys/cygwin.h>
45 #define FIO_FD_INVALID -1
46 #define FIO_FD_CONSOLE_IN -2
47 #define FIO_FD_CONSOLE_OUT -3
65 for (i = 3; i < 10; ++i)
129 if (flags & FILEIO_O_CREAT)
131 if (flags & FILEIO_O_EXCL)
133 if (flags & FILEIO_O_TRUNC)
135 if (flags & FILEIO_O_APPEND)
137 if (flags & FILEIO_O_RDONLY)
139 if (flags & FILEIO_O_WRONLY)
141 if (flags & FILEIO_O_RDWR)
158 if (mode & FILEIO_S_IFREG)
160 if (mode & FILEIO_S_IFDIR)
162 if (mode & FILEIO_S_IFCHR)
165 if (mode & FILEIO_S_IRUSR)
167 if (mode & FILEIO_S_IWUSR)
169 if (mode & FILEIO_S_IXUSR)
172 if (mode & FILEIO_S_IRGRP)
176 if (mode & FILEIO_S_IWGRP)
180 if (mode & FILEIO_S_IXGRP)
183 if (mode & FILEIO_S_IROTH)
186 if (mode & FILEIO_S_IWOTH)
190 if (mode & FILEIO_S_IXOTH)
203 case FILEIO_SEEK_SET:
206 case FILEIO_SEEK_CUR:
209 case FILEIO_SEEK_END:
224 if (!buf || !*buf || !**buf || !retlong)
226 c = strchr (*buf,
',');
230 c = strchr (*buf,
'\0');
231 while (strchr (
"+-", **buf))
237 for (*retlong = 0; **buf; ++*buf)
240 if (**buf >=
'0' && **buf <=
'9')
241 *retlong += **buf -
'0';
242 else if (**buf >=
'a' && **buf <=
'f')
243 *retlong += **buf -
'a' + 10;
244 else if (**buf >=
'A' && **buf <=
'F')
245 *retlong += **buf -
'A' + 10;
264 *retint = (
long) retlong;
274 if (!buf || !*buf || !**buf || !ptrval || !length)
276 c = strchr (*buf,
'/');
286 *length = (
int) retlong;
306 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
307 static struct sigaction remote_fio_sa;
308 static struct sigaction remote_fio_osa;
316 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
317 remote_fio_sa.sa_handler = SIG_IGN;
318 sigemptyset (&remote_fio_sa.sa_mask);
319 remote_fio_sa.sa_flags = 0;
320 sigaction (SIGINT, &remote_fio_sa, &remote_fio_osa);
329 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
330 remote_fio_sa.sa_handler = sigint_func;
331 sigemptyset (&remote_fio_sa.sa_mask);
332 remote_fio_sa.sa_flags = 0;
333 sigaction (SIGINT, &remote_fio_sa, NULL);
335 signal (SIGINT, sigint_func);
342 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
343 sigaction (SIGINT, &remote_fio_osa, NULL);
359 remote_fio_ctrl_c_flag = 1;
360 if (!remote_fio_no_longjmp)
377 sprintf (buf + strlen (buf),
"%x", retcode);
378 if (error || remote_fio_ctrl_c_flag)
380 if (error && remote_fio_ctrl_c_flag)
381 error = FILEIO_EINTR;
387 sprintf (buf + strlen (buf),
",%x", error);
388 if (remote_fio_ctrl_c_flag)
453 pathname = alloca (length);
463 if (!stat (pathname, &st))
465 if (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
470 if (S_ISDIR (st.st_mode)
471 && ((flags & O_WRONLY) == O_WRONLY || (flags & O_RDWR) == O_RDWR))
478 remote_fio_no_longjmp = 1;
509 remote_fio_no_longjmp = 1;
525 off_t old_offset, new_offset;
552 length = (size_t) num;
561 static char *remaining_buf = NULL;
562 static int remaining_length = 0;
567 remote_fio_no_longjmp = 1;
568 if (remaining_length > length)
570 memcpy (buffer, remaining_buf, length);
571 memmove (remaining_buf, remaining_buf + length,
572 remaining_length - length);
573 remaining_length -= length;
578 memcpy (buffer, remaining_buf, remaining_length);
579 xfree (remaining_buf);
580 remaining_buf = NULL;
581 ret = remaining_length;
598 remote_fio_no_longjmp = 1;
599 if (ret > 0 && (
size_t)ret > length)
601 remaining_buf = (
char *)
xmalloc (ret - length);
602 remaining_length = ret - length;
603 memcpy (remaining_buf, buffer + length, remaining_length);
616 old_offset = lseek (fd, 0,
SEEK_CUR);
617 remote_fio_no_longjmp = 1;
618 ret =
read (fd, buffer, length);
619 if (ret < 0 && errno == EINTR)
621 new_offset = lseek (fd, 0,
SEEK_CUR);
624 if (old_offset != new_offset)
625 ret = new_offset - old_offset;
680 length = (size_t) num;
690 remote_fio_no_longjmp = 1;
699 (
char *) buffer, length);
704 ret = write (fd, buffer, length);
705 if (ret < 0 && errno == EACCES)
751 offset = (off_t) lnum;
764 remote_fio_no_longjmp = 1;
765 ret = lseek (fd, offset, flag);
767 if (ret == (off_t) -1)
777 int old_len, new_len;
778 char *oldpath, *newpath;
780 struct stat ost, nst;
797 oldpath = alloca (old_len);
805 newpath = alloca (new_len);
813 of = stat (oldpath, &ost);
814 nf = stat (newpath, &nst);
815 if ((!of && !S_ISREG (ost.st_mode) && !S_ISDIR (ost.st_mode))
816 || (!nf && !S_ISREG (nst.st_mode) && !S_ISDIR (nst.st_mode)))
822 remote_fio_no_longjmp = 1;
823 ret = rename (oldpath, newpath);
830 if (errno == ENOTEMPTY)
836 if (!of && !nf && S_ISDIR (nst.st_mode))
838 if (S_ISREG (ost.st_mode))
842 char oldfullpath[PATH_MAX];
843 char newfullpath[PATH_MAX];
846 cygwin_conv_path (CCP_WIN_A_TO_POSIX, oldpath, oldfullpath,
848 cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
850 len = strlen (oldfullpath);
851 if (IS_DIR_SEPARATOR (newfullpath[len])
852 && !filename_ncmp (oldfullpath, newfullpath, len))
883 pathname = alloca (length);
892 if (!stat (pathname, &st) && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
898 remote_fio_no_longjmp = 1;
899 ret = unlink (pathname);
933 pathname = alloca (namelength);
940 remote_fio_no_longjmp = 1;
941 ret = stat (pathname, &st);
949 if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
1000 remote_fio_no_longjmp = 1;
1004 memset (&st, 0,
sizeof (st));
1008 st.st_uid = getuid ();
1011 st.st_gid = getgid ();
1013 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1014 st.st_blksize = 512;
1016 #if HAVE_STRUCT_STAT_ST_BLOCKS
1019 if (!gettimeofday (&tv, NULL))
1020 st.st_atime = st.st_mtime = st.st_ctime = tv.tv_sec;
1022 st.st_atime = st.st_mtime = st.st_ctime = (time_t) 0;
1026 ret = fstat (fd, &st);
1054 struct fio_timeval ftv;
1076 remote_fio_no_longjmp = 1;
1077 ret = gettimeofday (&tv, NULL);
1111 remote_fio_no_longjmp = 1;
1122 char *cmdline = NULL;
1134 cmdline = alloca (length);
1146 if (!remote_fio_system_call_allowed)
1155 remote_fio_no_longjmp = 1;
1156 ret = system (cmdline);
1188 char *buf = buf_arg;
1194 c = strchr (++buf,
',');
1198 c = strchr (buf,
'\0');
1241 if (ctrlc_pending_p)
1246 remote_fio_ctrl_c_flag = 1;
1247 remote_fio_no_longjmp = 0;
1252 remote_fio_ctrl_c_flag = 0;
1253 remote_fio_no_longjmp = 0;
1316 memset (st, 0,
sizeof (
struct stat));
1326 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1329 #if HAVE_STRUCT_STAT_ST_BLOCKS
1344 int val = strtoul (args, &arg_end, 10);
1346 if (*args && *arg_end ==
'\0')
1348 remote_fio_system_call_allowed = !!val;
1352 error (
_(
"Illegal argument for \"set remote system-call-allowed\" command"));
1359 error (
_(
"Garbage after \"show remote "
1360 "system-call-allowed\" command: `%s'"), args);
1362 remote_fio_system_call_allowed ?
"" :
"not ");
1369 sigint_fileio_token =
1374 _(
"Set if the host system(3) call is allowed for the target."),
1375 &remote_set_cmdlist);
1378 _(
"Show if the host system(3) call is allowed for the target."),
1379 &remote_show_cmdlist);
static int remote_fileio_resize_fd_map(void)
ssize_t read(int fd, void *buf, size_t count)
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
static mode_t remote_fileio_to_host_mode(fio_mode_t fnum)
static void remote_fileio_badfd(void)
#define FIO_FD_CONSOLE_IN
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
static struct @138 remote_fio_func_map[]
static unsigned int remote_fileio_to_host_uint(fio_uint_t fnum)
int catch_exceptions(struct ui_out *uiout, catch_exceptions_ftype *func, void *func_args, return_mask mask)
static void remote_fileio_return_errno(int retcode)
static void remote_fileio_sig_exit(void)
struct ui_file * gdb_stdtargin
static void remote_fileio_func_unlink(char *buf)
static void remote_fileio_func_close(char *buf)
static int do_remote_fileio_request(struct ui_out *uiout, void *buf_arg)
static struct cmd_list_element * remote_show_cmdlist
static int remote_fileio_extract_int(char **buf, long *retint)
int putpkt(const char *buf)
static void remote_fileio_func_gettimeofday(char *buf)
void initialize_remote_fileio(struct cmd_list_element *remote_set_cmdlist, struct cmd_list_element *remote_show_cmdlist)
static int remote_fileio_next_free_fd(void)
static void remote_fileio_func_rename(char *buf)
static void async_remote_fileio_interrupt(gdb_client_data arg)
static void remote_fileio_sig_init(void)
static void remote_fileio_reply(int retcode, int error)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
static void remote_fileio_func_system(char *buf)
static struct @137 remote_fio_data
static void remote_fileio_func_write(char *buf)
static struct async_signal_handler * sigint_fileio_token
static void host_to_fileio_time(time_t num, fio_time_t fnum)
static void host_to_fileio_uint(long num, fio_uint_t fnum)
static void show_system_call_allowed(char *args, int from_tty)
static int remote_fileio_extract_long(char **buf, LONGEST *retlong)
void host_to_fileio_stat(struct stat *st, struct fio_stat *fst)
#define FIO_FD_CONSOLE_OUT
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
int host_to_fileio_error(int error)
static mode_t remote_fileio_mode_to_host(long mode, int open_call)
async_signal_handler * create_async_signal_handler(sig_handler_func *proc, gdb_client_data client_data)
static time_t remote_fileio_to_host_time(fio_time_t fnum)
void printf_unfiltered(const char *format,...)
void remote_fileio_reset(void)
static void host_to_bigendian(LONGEST num, char *buf, int bytes)
static void remote_fileio_sig_set(void(*sigint_func)(int))
static int remote_fileio_init_fd_map(void)
static void remote_fileio_func_lseek(char *buf)
PTR xrealloc(PTR ptr, size_t size)
static int remote_fileio_fd_to_targetfd(int fd)
const char const char int
static ULONGEST remote_fileio_to_host_ulong(fio_ulong_t fnum)
static int remote_fio_system_call_allowed
static void remote_fileio_func_open(char *buf)
static int remote_fileio_map_fd(int target_fd)
static void remote_fileio_func_read(char *buf)
static void remote_fileio_to_fio_long(LONGEST num, fio_long_t fnum)
static void remote_fileio_close_target_fd(int target_fd)
static void remote_fileio_ioerror(void)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
static void(* remote_fio_ofunc)(int)
static int remote_fio_ctrl_c_flag
void ui_file_write(struct ui_file *file, const char *buf, long length_buf)
long ui_file_read(struct ui_file *file, char *buf, long length_buf)
static void remote_fileio_func_fstat(char *buf)
static void remote_fileio_return_success(int retcode)
static int remote_fileio_oflags_to_host(long flags)
struct ui_file * gdb_stdtarg
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
void remote_fileio_to_host_stat(struct fio_stat *fst, struct stat *st)
unsigned long long ULONGEST
void gdb_call_async_signal_handler(struct async_signal_handler *handler, int immediate_p)
static struct cmd_list_element * remote_set_cmdlist
static void remote_fileio_to_fio_timeval(struct timeval *tv, struct fio_timeval *ftv)
struct ui_file * gdb_stdtargerr
static void remote_fileio_ctrl_c_signal_handler(int signo)
void gdb_flush(struct ui_file *file)
struct ui_out * current_uiout
static void set_system_call_allowed(char *args, int from_tty)
static void remote_fileio_func_stat(char *buf)
static int remote_fileio_seek_flag_to_host(long num, int *flag)
void error(const char *fmt,...)
static void remote_fileio_func_isatty(char *buf)
static int remote_fileio_extract_ptr_w_len(char **buf, CORE_ADDR *ptrval, int *length)
const ULONGEST const LONGEST len
void remote_fileio_request(char *buf, int ctrlc_pending_p)
static int remote_fio_no_longjmp