Re: Reading from socket: recv works read doesn't. Why ?

Linus Torvalds (torvalds@transmeta.com)
Thu, 6 Mar 1997 10:07:37 -0800 (PST)


On Thu, 6 Mar 1997, Luca Lizzeri wrote:
>
> I am porting a motif application from SunOs to Linux.
>
> I have two processes communicating over unix domain sockets.
>
> On the Sun everything works fine (apart from permitting double freeing a
> memory area and the like :), on Linux I have a problem with read():
>
> socketpair(PF_UNIX, SOCK_STREAM, , 0, [8, 9]) = 0
> fork() = 380
> close(9) = 0
> oldselect(1024, [8], NULL, NULL, {3600, 0}) = 1 (in [8], left {3598, 910000})
> read(8, 0xbffff67c, 4096) = -1 EFAULT (Bad address)
>
> read() returns EFAULT whether the read buffer is allocated on the stack
> or is malloc'ed (both of size 4096).

At least in the above example the kernel is certainly correct: you should
get an EFAULT, because you certainly have _not_ allocated 4096 bytes of
space on the stack (the buffer address of the read is 0xbffff67c, and the
stack ends at 0xbfffffff, so you only have about 2.5kB worth of buffers
for it).

Linus