* strcpy returns NULL pointer and not destination pointer
@ 2006-05-03 13:38 Bob Picco
2006-05-03 18:08 ` Chen, Kenneth W
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Bob Picco @ 2006-05-03 13:38 UTC (permalink / raw)
To: linux-ia64
Hi Ken:
I'm assuming you can speak to this because your email address is in
memcpy_mck.S.
The removal of -ffreestanding compiler flag in 2.6.17-rcX (commit id
6edfba1b33c701108717f4e036320fc39abe1912) causes strcpy calls
with a known size for the source string to be replaced with memcpy which
is faster. ia64 memcpy has return values which are unlike stdlibc and
the other arch memcpy routines examined by me in the kernel. The ia64 return
values are 0 for success and number of bytes copied for failure. Thus any
instance of pointer = strcpy(dest, "some string") has zero assigned to
pointer. I detected this when testing kgdb on 2.6.17-rc3.
The implementation in memcpy_mck.S doesn't leave a single scratch
register or predicate. I didn't pursue very long for a solution.
thanks,
bob
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: strcpy returns NULL pointer and not destination pointer
2006-05-03 13:38 strcpy returns NULL pointer and not destination pointer Bob Picco
@ 2006-05-03 18:08 ` Chen, Kenneth W
2006-05-03 18:30 ` Bob Picco
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Chen, Kenneth W @ 2006-05-03 18:08 UTC (permalink / raw)
To: linux-ia64
Bob Picco wrote on Wednesday, May 03, 2006 6:38 AM
> The removal of -ffreestanding compiler flag in 2.6.17-rcX (commit id
> 6edfba1b33c701108717f4e036320fc39abe1912) causes strcpy calls
> with a known size for the source string to be replaced with memcpy which
> is faster. ia64 memcpy has return values which are unlike stdlibc and
> the other arch memcpy routines examined by me in the kernel. The ia64 return
> values are 0 for success and number of bytes copied for failure. Thus any
> instance of pointer = strcpy(dest, "some string") has zero assigned to
> pointer. I detected this when testing kgdb on 2.6.17-rc3.
>
> The implementation in memcpy_mck.S doesn't leave a single scratch
> register or predicate. I didn't pursue very long for a solution.
I thought I fixed that about 3 years ago:
http://marc.theaimsgroup.com/?l=linux-ia64&m\x105590709805435&w=2
Did it fall through the crack? I'm not sure what's going on.
- Ken
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: strcpy returns NULL pointer and not destination pointer
2006-05-03 13:38 strcpy returns NULL pointer and not destination pointer Bob Picco
2006-05-03 18:08 ` Chen, Kenneth W
@ 2006-05-03 18:30 ` Bob Picco
2006-05-03 18:46 ` Chen, Kenneth W
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Bob Picco @ 2006-05-03 18:30 UTC (permalink / raw)
To: linux-ia64
Chen, Kenneth W wrote: [Wed May 03 2006, 02:08:47PM EDT]
> Bob Picco wrote on Wednesday, May 03, 2006 6:38 AM
> > The removal of -ffreestanding compiler flag in 2.6.17-rcX (commit id
> > 6edfba1b33c701108717f4e036320fc39abe1912) causes strcpy calls
> > with a known size for the source string to be replaced with memcpy which
> > is faster. ia64 memcpy has return values which are unlike stdlibc and
> > the other arch memcpy routines examined by me in the kernel. The ia64 return
> > values are 0 for success and number of bytes copied for failure. Thus any
> > instance of pointer = strcpy(dest, "some string") has zero assigned to
> > pointer. I detected this when testing kgdb on 2.6.17-rc3.
> >
> > The implementation in memcpy_mck.S doesn't leave a single scratch
> > register or predicate. I didn't pursue very long for a solution.
>
> I thought I fixed that about 3 years ago:
>
> http://marc.theaimsgroup.com/?l=linux-ia64&m\x105590709805435&w=2
>
> Did it fall through the crack? I'm not sure what's going on.
>
> - Ken
It looks to have definitely fallen through a crack or two.
I applied to rc3 and boot tested for you. I assume you'll post patch again.
bob
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: strcpy returns NULL pointer and not destination pointer
2006-05-03 13:38 strcpy returns NULL pointer and not destination pointer Bob Picco
2006-05-03 18:08 ` Chen, Kenneth W
2006-05-03 18:30 ` Bob Picco
@ 2006-05-03 18:46 ` Chen, Kenneth W
2006-05-03 18:48 ` Matthew Wilcox
2006-05-03 18:53 ` Chen, Kenneth W
4 siblings, 0 replies; 6+ messages in thread
From: Chen, Kenneth W @ 2006-05-03 18:46 UTC (permalink / raw)
To: linux-ia64
Bob Picco wrote on Wednesday, May 03, 2006 11:31 AM
> Chen, Kenneth W wrote: [Wed May 03 2006, 02:08:47PM EDT]
> > Bob Picco wrote on Wednesday, May 03, 2006 6:38 AM
> > > The removal of -ffreestanding compiler flag in 2.6.17-rcX (commit id
> > > 6edfba1b33c701108717f4e036320fc39abe1912) causes strcpy calls
> > > with a known size for the source string to be replaced with memcpy which
> > > is faster. ia64 memcpy has return values which are unlike stdlibc and
> > > the other arch memcpy routines examined by me in the kernel. The ia64 return
> > > values are 0 for success and number of bytes copied for failure. Thus any
> > > instance of pointer = strcpy(dest, "some string") has zero assigned to
> > > pointer. I detected this when testing kgdb on 2.6.17-rc3.
> > >
> > > The implementation in memcpy_mck.S doesn't leave a single scratch
> > > register or predicate. I didn't pursue very long for a solution.
> >
> > I thought I fixed that about 3 years ago:
> >
> > http://marc.theaimsgroup.com/?l=linux-ia64&m\x105590709805435&w=2
> >
> > Did it fall through the crack? I'm not sure what's going on.
>
> It looks to have definitely fallen through a crack or two.
>
> I applied to rc3 and boot tested for you. I assume you'll post patch again.
Wow, 3 years ago patch still applies. I'm impressed, that doesn't happen
very often ;-)
Here is an updated version, with comments updated (bcopy was removed).
[patch] fix return value of memcpy
Signed-off-by: Ken Chen <kenneth.w.chen@intel.com>
--- ./arch/ia64/lib/memcpy_mck.S.orig 2006-03-19 21:53:29.000000000 -0800
+++ ./arch/ia64/lib/memcpy_mck.S 2006-05-03 12:30:20.000000000 -0700
@@ -6,7 +6,9 @@
* in1: source address
* in2: number of bytes to copy
* Output:
- * 0 if success, or number of byte NOT copied if error occurred.
+ * for memcpy: retrun dest
+ * for copy_user: return 0 if success,
+ * or number of byte NOT copied if error occurred.
*
* Copyright (C) 2002 Intel Corp.
* Copyright (C) 2002 Ken Chen <kenneth.w.chen@intel.com>
@@ -73,6 +75,7 @@ GLOBAL_ENTRY(memcpy)
and r28=0x7,in0
and r29=0x7,in1
mov f6ð
+ mov retval=in0
br.cond.sptk .common_code
;;
END(memcpy)
@@ -84,7 +87,7 @@ GLOBAL_ENTRY(__copy_user)
mov f6ñ
mov saved_in0=in0 // save dest pointer
mov saved_in1=in1 // save src pointer
- mov saved_in2=in2 // save len
+ mov retval=r0 // initialize return value
;;
.common_code:
cmp.gt p15,p0=8,in2 // check for small size
@@ -92,7 +95,7 @@ GLOBAL_ENTRY(__copy_user)
cmp.ne p14,p0=0,r29 // check src alignment
add src0=0,in1
sub r30=8,r28 // for .align_dest
- mov retval=r0 // initialize return value
+ mov saved_in2=in2 // save len
;;
add dst0=0,in0
add dst1=1,in0 // dest odd index
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: strcpy returns NULL pointer and not destination pointer
2006-05-03 13:38 strcpy returns NULL pointer and not destination pointer Bob Picco
` (2 preceding siblings ...)
2006-05-03 18:46 ` Chen, Kenneth W
@ 2006-05-03 18:48 ` Matthew Wilcox
2006-05-03 18:53 ` Chen, Kenneth W
4 siblings, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2006-05-03 18:48 UTC (permalink / raw)
To: linux-ia64
On Wed, May 03, 2006 at 11:46:07AM -0700, Chen, Kenneth W wrote:
> - * 0 if success, or number of byte NOT copied if error occurred.
> + * for memcpy: retrun dest
typo
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: strcpy returns NULL pointer and not destination pointer
2006-05-03 13:38 strcpy returns NULL pointer and not destination pointer Bob Picco
` (3 preceding siblings ...)
2006-05-03 18:48 ` Matthew Wilcox
@ 2006-05-03 18:53 ` Chen, Kenneth W
4 siblings, 0 replies; 6+ messages in thread
From: Chen, Kenneth W @ 2006-05-03 18:53 UTC (permalink / raw)
To: linux-ia64
Matthew Wilcox wrote on Wednesday, May 03, 2006 11:49 AM
> On Wed, May 03, 2006 at 11:46:07AM -0700, Chen, Kenneth W wrote:
> > - * 0 if success, or number of byte NOT copied if error occurred.
> > + * for memcpy: retrun dest
>
> typo
Thank you. I need a spell-o-matic checker :-)
[patch] fix return value of memcpy
Signed-off-by: Ken Chen <kenneth.w.chen@intel.com>
--- ./arch/ia64/lib/memcpy_mck.S.orig 2006-03-19 21:53:29.000000000 -0800
+++ ./arch/ia64/lib/memcpy_mck.S 2006-05-03 12:30:20.000000000 -0700
@@ -6,7 +6,9 @@
* in1: source address
* in2: number of bytes to copy
* Output:
- * 0 if success, or number of byte NOT copied if error occurred.
+ * for memcpy: return dest
+ * for copy_user: return 0 if success,
+ * or number of byte NOT copied if error occurred.
*
* Copyright (C) 2002 Intel Corp.
* Copyright (C) 2002 Ken Chen <kenneth.w.chen@intel.com>
@@ -73,6 +75,7 @@ GLOBAL_ENTRY(memcpy)
and r28=0x7,in0
and r29=0x7,in1
mov f6ð
+ mov retval=in0
br.cond.sptk .common_code
;;
END(memcpy)
@@ -84,7 +87,7 @@ GLOBAL_ENTRY(__copy_user)
mov f6ñ
mov saved_in0=in0 // save dest pointer
mov saved_in1=in1 // save src pointer
- mov saved_in2=in2 // save len
+ mov retval=r0 // initialize return value
;;
.common_code:
cmp.gt p15,p0=8,in2 // check for small size
@@ -92,7 +95,7 @@ GLOBAL_ENTRY(__copy_user)
cmp.ne p14,p0=0,r29 // check src alignment
add src0=0,in1
sub r30=8,r28 // for .align_dest
- mov retval=r0 // initialize return value
+ mov saved_in2=in2 // save len
;;
add dst0=0,in0
add dst1=1,in0 // dest odd index
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-05-03 18:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-03 13:38 strcpy returns NULL pointer and not destination pointer Bob Picco
2006-05-03 18:08 ` Chen, Kenneth W
2006-05-03 18:30 ` Bob Picco
2006-05-03 18:46 ` Chen, Kenneth W
2006-05-03 18:48 ` Matthew Wilcox
2006-05-03 18:53 ` Chen, Kenneth W
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox