From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18210 invoked by alias); 18 Sep 2005 02:40:54 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 18138 invoked by uid 22791); 18 Sep 2005 02:40:16 -0000 Received: from qproxy.gmail.com (HELO qproxy.gmail.com) (72.14.204.194) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sun, 18 Sep 2005 02:40:16 +0000 Received: by qproxy.gmail.com with SMTP id i38so116809qbh for ; Sat, 17 Sep 2005 19:40:14 -0700 (PDT) Received: by 10.65.38.2 with SMTP id q2mr17179qbj; Sat, 17 Sep 2005 19:40:14 -0700 (PDT) Received: by 10.65.20.15 with HTTP; Sat, 17 Sep 2005 19:40:14 -0700 (PDT) Message-ID: <7f45d939050917194069e70603@mail.gmail.com> Date: Sun, 18 Sep 2005 02:40:00 -0000 From: Shaun Jackman Reply-To: Shaun Jackman To: Shaun Jackman , Richard Earnshaw , gdb-patches@sources.redhat.com Subject: Re: sim/arm/armos.c: IsTTY [PATCH] In-Reply-To: <20050918011413.GO8777@nevyn.them.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_30509_23097561.1127011214043" References: <7f45d9390508151204ca0b146@mail.gmail.com> <20050830023718.GB16189@nevyn.them.org> <7f45d93905090709516f912861@mail.gmail.com> <1126170388.18092.16.camel@pc960.cambridge.arm.com> <7f45d93905090910237c63acf0@mail.gmail.com> <20050917223728.GL8777@nevyn.them.org> <7f45d939050917163241caaa41@mail.gmail.com> <20050918011413.GO8777@nevyn.them.org> X-SW-Source: 2005-09/txt/msg00150.txt.bz2 ------=_Part_30509_23097561.1127011214043 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-length: 6352 2005/9/17, Daniel Jacobowitz : > It only now occurs to me to ask if you have a copyright assignment on > file with the FSF - do you? I don't see one listed. Sorry for not > catching this potential problem earlier. No, I haven't. I'll reply privately with a fax number if that's possible. Otherwise, I'll give you my address for mashed-tree correspondance. > Space before the parens here. ... > I'd appreciate it if you didn't use the return value of assignment this > way; it's too easy to assume a typo. ... > Space before parens, braces get indented. ... > And operators go at the beginning of the line. Looks odd at first, but > you get used to it. OK. Cheers, Shaun 2005-09-17 Shaun Jackman * sim/arm/armos.c: Include limits.h (unlink): Remove this macro. It is unused in this file and conflicts with sim_callback->unlink. (PATH_MAX): Define as 1024 if not already defined. (ReadFileName): New function. (SWIopen): Fix a potential buffer overflow. (SWIremove): New function. (SWIrename): Ditto. (ARMul_OSHandleSWI): Handle the RDP calls SWI_IsTTY, SWI_Remove, and SWI_Rename, as well as the RDI calls AngelSWI_Reason_IsTTY, AngelSWI_Reason_Remove, and AngelSWI_Reason_Rename. Index: sim/arm/armos.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/sim/arm/armos.c,v retrieving revision 1.22 diff -u -r1.22 armos.c --- sim/arm/armos.c 12 May 2005 07:36:58 -0000 1.22 +++ sim/arm/armos.c 18 Sep 2005 02:16:45 -0000 @@ -27,6 +27,7 @@ =20 #include #include +#include #include #include "targ-vals.h" =20 @@ -34,10 +35,6 @@ #define TARGET_O_BINARY 0 #endif =20 -#ifdef __STDC__ -#define unlink(s) remove(s) -#endif - #ifdef HAVE_UNISTD_H #include /* For SEEK_SET etc. */ #endif @@ -89,6 +86,9 @@ #define FOPEN_MAX 64 #endif #define UNIQUETEMPS 256 +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif =20 /* OS private Information. */ =20 @@ -299,22 +299,35 @@ while (temp !=3D 0); } =20 +static int +ReadFileName (ARMul_State * state, char *buf, ARMword src, size_t n) +{ + struct OSblock *OSptr =3D (struct OSblock *) state->OSptr; + char *p =3D buf; + + while (n--) + if ((*p++ =3D ARMul_SafeReadByte (state, src++)) =3D=3D '\0') + return 0; + OSptr->ErrorNo =3D cb_host_to_target_errno(sim_callback, ENAMETOOLONG); + state->Reg[0] =3D -1; + return -1; +} + static void SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags) { struct OSblock *OSptr =3D (struct OSblock *) state->OSptr; - char dummy[2000]; + char buf[PATH_MAX]; int flags; - int i; =20 - for (i =3D 0; (dummy[i] =3D ARMul_SafeReadByte (state, name + i)); i++) - ; + if (ReadFileName (state, buf, name, sizeof buf) =3D=3D -1) + return; =20 /* Now we need to decode the Demon open mode. */ flags =3D translate_open_mode[SWIflags]; =20 /* Filename ":tt" is special: it denotes stdin/out. */ - if (strcmp (dummy, ":tt") =3D=3D 0) + if (strcmp (buf, ":tt") =3D=3D 0) { if (flags =3D=3D TARGET_O_RDONLY) /* opening tty "r" */ state->Reg[0] =3D 0; /* stdin */ @@ -323,7 +336,7 @@ } else { - state->Reg[0] =3D sim_callback->open (sim_callback, dummy, flags); + state->Reg[0] =3D sim_callback->open (sim_callback, buf, flags); OSptr->ErrorNo =3D sim_callback->get_errno (sim_callback); } } @@ -403,6 +416,33 @@ OSptr->ErrorNo =3D sim_callback->get_errno (sim_callback); } =20 +static void +SWIremove (ARMul_State * state, ARMword path) +{ + char buf[PATH_MAX]; + + if (ReadFileName (state, buf, path, sizeof buf) !=3D -1) + { + struct OSblock *OSptr =3D (struct OSblock *) state->OSptr; + state->Reg[0] =3D sim_callback->unlink (sim_callback, buf); + OSptr->ErrorNo =3D sim_callback->get_errno (sim_callback); + } +} + +static void +SWIrename (ARMul_State * state, ARMword old, ARMword new) +{ + char oldbuf[PATH_MAX], newbuf[PATH_MAX]; + + if (ReadFileName (state, oldbuf, old, sizeof oldbuf) !=3D -1 + && ReadFileName (state, newbuf, new, sizeof newbuf) !=3D -1) + { + struct OSblock *OSptr =3D (struct OSblock *) state->OSptr; + state->Reg[0] =3D sim_callback->rename (sim_callback, oldbuf, newbuf= ); + OSptr->ErrorNo =3D sim_callback->get_errno (sim_callback); + } +} + /* The emulator calls this routine when a SWI instruction is encuntered. The parameter passed is the SWI number (lower 24 bits of the instruction). */ =20 @@ -544,6 +584,30 @@ state->Emulate =3D FALSE; break; =20 + case SWI_Remove: + if (swi_mask & SWI_MASK_DEMON) + SWIremove (state, state->Reg[0]); + else + unhandled =3D TRUE; + break; + + case SWI_Rename: + if (swi_mask & SWI_MASK_DEMON) + SWIrename (state, state->Reg[0], state->Reg[1]); + else + unhandled =3D TRUE; + break; + + case SWI_IsTTY: + if (swi_mask & SWI_MASK_DEMON) + { + state->Reg[0] =3D sim_callback->isatty (sim_callback, state->Reg[0]); + OSptr->ErrorNo =3D sim_callback->get_errno (sim_callback); + } + else + unhandled =3D TRUE; + break; + /* Handle Angel SWIs as well as Demon ones. */ case AngelSWI_ARM: case AngelSWI_Thumb: @@ -566,10 +630,7 @@ =20=09=20=20 /* Unimplemented reason codes. */ case AngelSWI_Reason_ReadC: - case AngelSWI_Reason_IsTTY: case AngelSWI_Reason_TmpNam: - case AngelSWI_Reason_Remove: - case AngelSWI_Reason_Rename: case AngelSWI_Reason_System: case AngelSWI_Reason_EnterSVC: default: @@ -684,6 +745,21 @@ ARMul_ReadWord (state, addr + 4), ARMul_ReadWord (state, addr + 8)); break; + + case AngelSWI_Reason_IsTTY: + state->Reg[0] =3D sim_callback->close (sim_callback, + ARMul_ReadWord (state, addr)); + OSptr->ErrorNo =3D sim_callback->get_errno (sim_callback); + break; + + case AngelSWI_Reason_Remove: + SWIremove (state, + ARMul_ReadWord (state, addr)); + + case AngelSWI_Reason_Rename: + SWIrename (state, + ARMul_ReadWord (state, addr), + ARMul_ReadWord (state, addr + 4)); } } else ------=_Part_30509_23097561.1127011214043 Content-Type: text/plain; name=sim-arm-swi.diff; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sim-arm-swi.diff" Content-length: 5381 2005-09-17 Shaun Jackman * sim/arm/armos.c: Include limits.h (unlink): Remove this macro. It is unused in this file and conflicts with sim_callback->unlink. (PATH_MAX): Define as 1024 if not already defined. (ReadFileName): New function. (SWIopen): Fix a potential buffer overflow. (SWIremove): New function. (SWIrename): Ditto. (ARMul_OSHandleSWI): Handle the RDP calls SWI_IsTTY, SWI_Remove, and SWI_Rename, as well as the RDI calls AngelSWI_Reason_IsTTY, AngelSWI_Reason_Remove, and AngelSWI_Reason_Rename. Index: sim/arm/armos.c =================================================================== RCS file: /cvs/src/src/sim/arm/armos.c,v retrieving revision 1.22 diff -u -r1.22 armos.c --- sim/arm/armos.c 12 May 2005 07:36:58 -0000 1.22 +++ sim/arm/armos.c 18 Sep 2005 02:16:45 -0000 @@ -27,6 +27,7 @@ #include #include +#include #include #include "targ-vals.h" @@ -34,10 +35,6 @@ #define TARGET_O_BINARY 0 #endif -#ifdef __STDC__ -#define unlink(s) remove(s) -#endif - #ifdef HAVE_UNISTD_H #include /* For SEEK_SET etc. */ #endif @@ -89,6 +86,9 @@ #define FOPEN_MAX 64 #endif #define UNIQUETEMPS 256 +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif /* OS private Information. */ @@ -299,22 +299,35 @@ while (temp != 0); } +static int +ReadFileName (ARMul_State * state, char *buf, ARMword src, size_t n) +{ + struct OSblock *OSptr = (struct OSblock *) state->OSptr; + char *p = buf; + + while (n--) + if ((*p++ = ARMul_SafeReadByte (state, src++)) == '\0') + return 0; + OSptr->ErrorNo = cb_host_to_target_errno(sim_callback, ENAMETOOLONG); + state->Reg[0] = -1; + return -1; +} + static void SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags) { struct OSblock *OSptr = (struct OSblock *) state->OSptr; - char dummy[2000]; + char buf[PATH_MAX]; int flags; - int i; - for (i = 0; (dummy[i] = ARMul_SafeReadByte (state, name + i)); i++) - ; + if (ReadFileName (state, buf, name, sizeof buf) == -1) + return; /* Now we need to decode the Demon open mode. */ flags = translate_open_mode[SWIflags]; /* Filename ":tt" is special: it denotes stdin/out. */ - if (strcmp (dummy, ":tt") == 0) + if (strcmp (buf, ":tt") == 0) { if (flags == TARGET_O_RDONLY) /* opening tty "r" */ state->Reg[0] = 0; /* stdin */ @@ -323,7 +336,7 @@ } else { - state->Reg[0] = sim_callback->open (sim_callback, dummy, flags); + state->Reg[0] = sim_callback->open (sim_callback, buf, flags); OSptr->ErrorNo = sim_callback->get_errno (sim_callback); } } @@ -403,6 +416,33 @@ OSptr->ErrorNo = sim_callback->get_errno (sim_callback); } +static void +SWIremove (ARMul_State * state, ARMword path) +{ + char buf[PATH_MAX]; + + if (ReadFileName (state, buf, path, sizeof buf) != -1) + { + struct OSblock *OSptr = (struct OSblock *) state->OSptr; + state->Reg[0] = sim_callback->unlink (sim_callback, buf); + OSptr->ErrorNo = sim_callback->get_errno (sim_callback); + } +} + +static void +SWIrename (ARMul_State * state, ARMword old, ARMword new) +{ + char oldbuf[PATH_MAX], newbuf[PATH_MAX]; + + if (ReadFileName (state, oldbuf, old, sizeof oldbuf) != -1 + && ReadFileName (state, newbuf, new, sizeof newbuf) != -1) + { + struct OSblock *OSptr = (struct OSblock *) state->OSptr; + state->Reg[0] = sim_callback->rename (sim_callback, oldbuf, newbuf); + OSptr->ErrorNo = sim_callback->get_errno (sim_callback); + } +} + /* The emulator calls this routine when a SWI instruction is encuntered. The parameter passed is the SWI number (lower 24 bits of the instruction). */ @@ -544,6 +584,30 @@ state->Emulate = FALSE; break; + case SWI_Remove: + if (swi_mask & SWI_MASK_DEMON) + SWIremove (state, state->Reg[0]); + else + unhandled = TRUE; + break; + + case SWI_Rename: + if (swi_mask & SWI_MASK_DEMON) + SWIrename (state, state->Reg[0], state->Reg[1]); + else + unhandled = TRUE; + break; + + case SWI_IsTTY: + if (swi_mask & SWI_MASK_DEMON) + { + state->Reg[0] = sim_callback->isatty (sim_callback, state->Reg[0]); + OSptr->ErrorNo = sim_callback->get_errno (sim_callback); + } + else + unhandled = TRUE; + break; + /* Handle Angel SWIs as well as Demon ones. */ case AngelSWI_ARM: case AngelSWI_Thumb: @@ -566,10 +630,7 @@ /* Unimplemented reason codes. */ case AngelSWI_Reason_ReadC: - case AngelSWI_Reason_IsTTY: case AngelSWI_Reason_TmpNam: - case AngelSWI_Reason_Remove: - case AngelSWI_Reason_Rename: case AngelSWI_Reason_System: case AngelSWI_Reason_EnterSVC: default: @@ -684,6 +745,21 @@ ARMul_ReadWord (state, addr + 4), ARMul_ReadWord (state, addr + 8)); break; + + case AngelSWI_Reason_IsTTY: + state->Reg[0] = sim_callback->close (sim_callback, + ARMul_ReadWord (state, addr)); + OSptr->ErrorNo = sim_callback->get_errno (sim_callback); + break; + + case AngelSWI_Reason_Remove: + SWIremove (state, + ARMul_ReadWord (state, addr)); + + case AngelSWI_Reason_Rename: + SWIrename (state, + ARMul_ReadWord (state, addr), + ARMul_ReadWord (state, addr + 4)); } } else ------=_Part_30509_23097561.1127011214043--