Re: write(2) fails for large sizes in 64 bit applications
Re: write(2) fails for large sizes in 64 bit applications
- Subject: Re: write(2) fails for large sizes in 64 bit applications
- From: Robert Homann <email@hidden>
- Date: Thu, 28 May 2009 13:18:38 +0200 (MEST)
On Thu, 28 May 2009, Anton Altaparmakov wrote:
> Hi,
Hi!
> Yes you are quite right. If you look in the kernel source code you
> can see that it is a hard limit...
>
> http://www.opensource.apple.com/source/xnu/xnu-1228.12.14/bsd/kern/sys_generic.c
>
> The write() system call in turn calls write_nocancel() which in turn
> calls dofilewrite() which at the top of the function contains:
>
> // LP64todo - do we want to raise this?
> if (nbyte > INT_MAX)
> return (EINVAL);
I see. I'd answer the question in the comment with a clear "yes" since
http://www.opengroup.org/onlinepubs/009695399/functions/write.html
states, "If the value of nbyte is greater than {SSIZE_MAX}, the result is
implementation-defined." The value of SSIZE_MAX is 2^63-1 in 64 bit mode,
so write() should not complain about invalid arguments when given large
numbers.
Of course, the cited standard only mentions what happens, or that
"something" happens, when nbyte is greater than SSIZE_MAX, but doesn't
mention smaller boundaries such as INT_MAX... Still, I think this issue
should be fixed by someone, either in code or in documentation.
>From what I can see in the code, I think dofilewrite() can be fixed rather
easily to work like what the standard says. (Please note that I am not
familiar with the kernel code at all, so my claim might sound a bit
shortsighted to you guys.) One way would be to return EINVAL like this:
if((!IS_64BIT_PROCESS(vfs_context_proc(ctx)) && nbyte > INT_MAX) ||
(IS_64BIT_PROCESS(vfs_context_proc(ctx)) && nbyte > SSIZE_MAX))
return (EINVAL);
I don't know if SSIZE_MAX is defined correctly at this point, but you get
the idea. Another way involves limiting the number of bytes to INT_MAX in
64 bit mode rather than failing, should the uio_*() functions not be able
to cope with larger values:
if(nbyte > INT_MAX)
{
if(!IS_64BIT_PROCESS(vfs_context_proc(ctx)) || nbyte > SSIZE_MAX)
return EINVAL;
nbyte=INT_MAX;
}
This way, write() would never write more than INT_MAX bytes, which is
perfectly OK, but it wouldn't fail anymore.
> Best regards,
>
> Anton
Best regards,
Robert Homann
--
Windows is not the answer.
Windows is the question.
The answer is "No".
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden