From patchwork Wed May 16 22:50:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julio Guerra X-Patchwork-Id: 27308 Received: (qmail 108939 invoked by alias); 16 May 2018 22:50:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 108211 invoked by uid 89); 16 May 2018 22:50:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=julio, UD:amazonses.com, fst X-HELO: a4-71.smtp-out.eu-west-1.amazonses.com Received: from a4-71.smtp-out.eu-west-1.amazonses.com (HELO a4-71.smtp-out.eu-west-1.amazonses.com) (54.240.4.71) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 May 2018 22:50:09 +0000 Subject: [PATCH] Remove the restriction of File I/O function open() to regular files only From: =?UTF-8?Q?Julio_Guerra?= To: =?UTF-8?Q?gdb-patches=40sourceware=2Eorg?= Cc: =?UTF-8?Q?Mike_Frysinger?= , =?UTF-8?Q?Pedro_Alves?= , =?UTF-8?Q?Julio_Guerra?= Date: Wed, 16 May 2018 22:50:06 +0000 Mime-Version: 1.0 References: <20180516225002.24380-1-julio@farjump.io> X-Original-Mailer: git-send-email 2.17.0 Message-ID: <010201636b2573af-0cdb68f4-b1a1-4bc4-89b4-ba2e907f5524-000000@eu-west-1.amazonses.com> X-SES-Outgoing: 2018.05.16-54.240.4.71 Feedback-ID: 1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-IsSubscribed: yes The major goal is being able to write advanced embedded testing functions, like: - reading/writing to a dedicated fifo between the embedded program and the host, instead of being restricted to the GDB console only. - mocking features based on host's (e.g. opening /dev/random). Tested with https://github.com/farjump/raspberry-pi/blob/ea31c48d7c7eed27d39fb1bec2d3a1d308cb8ae7/src/semihosting/semihosting.c Also answers to an old RFC I did on the ML: https://sourceware.org/ml/gdb/2016-07/msg00003.html 2018-05-16 Julio Guerra * remote-fileio.c: allow using File I/O function open() with special files. Signed-off-by: Julio Guerra --- gdb/ChangeLog | 5 +++++ gdb/remote-fileio.c | 24 ------------------------ 2 files changed, 5 insertions(+), 24 deletions(-) -- 2.17.0 diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 57a4075a12..7217be67b6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-05-16 Julio Guerra + + * remote-fileio.c: allow using File I/O function open() with special + files. + 2018-05-15 Tamar Christina PR binutils/21446 diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index 4c648a9c83..fa3cb15033 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -407,24 +407,6 @@ remote_fileio_func_open (char *buf) return; } - /* Check if pathname exists and is not a regular file or directory. If so, - return an appropriate error code. Same for trying to open directories - for writing. */ - if (!stat (pathname, &st)) - { - if (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode)) - { - remote_fileio_reply (-1, FILEIO_ENODEV); - return; - } - if (S_ISDIR (st.st_mode) - && ((flags & O_WRONLY) == O_WRONLY || (flags & O_RDWR) == O_RDWR)) - { - remote_fileio_reply (-1, FILEIO_EISDIR); - return; - } - } - fd = gdb_open_cloexec (pathname, flags, mode); if (fd < 0) { @@ -885,12 +867,6 @@ remote_fileio_func_stat (char *buf) remote_fileio_return_errno (-1); return; } - /* Only operate on regular files and directories. */ - if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode)) - { - remote_fileio_reply (-1, FILEIO_EACCES); - return; - } if (statptr) { host_to_fileio_stat (&st, &fst);