* Strange error in STREAMS code
@ 1994-11-13 18:59 Steve Tate
1994-11-13 23:24 ` Steve Tate
0 siblings, 1 reply; 7+ messages in thread
From: Steve Tate @ 1994-11-13 18:59 UTC (permalink / raw)
Ok, I admit it.... I'm stumped. I have a weird thing going on in a
STREAMS driver for an Alpha machine running OSF/1, and I don't know what
the problem is. Hopefully someone here can clarify it for me... I fixed
the problem so that the code works, but I'd really like to understand what
was happening. Here's the original code (the code is really just the one
if statement, and the others are for writing to the kernel log).
DLOG("ppp_if: SIOC[GS]ETNPMODE cmd %x\n", i->ioc_cmd);
DLOG("ppp_if: Reference cmd %x\n", SIOCSETNPMODE);
if (i->ioc_cmd == SIOCSETNPMODE) {
DLOG("ppp_if: SETNPMODE really is SETNPMODE!\n", 0);
This produces the following log file entries:
Nov 13 11:40:22 zaphod vmunix: ppp_if: SIOC[GS]ETNPMODE cmd 80087091
Nov 13 11:40:22 zaphod vmunix: ppp_if: Reference cmd 80087091
Nov 13 11:40:22 zaphod vmunix: ppp_if: SETNPMODE about to reply with an M_IOCACK
So it looks like i->ioc_cmd and SIOCSETNPMODE are equal, and yet the
condition in the if is not true (since the next log entry is not made).
Experience tells me that it's some sort of type mismatch or something
(one is getting sign-extended and the other isn't or something), so I
look back at all the definitions. i->ioc_cmd is an int, and SIOCSETNPMODE
is an ioctl code defined with _IOW(..), which is simply a constant
expression that should evaluate to a constant of type int. So it
seems like that can't possibly be the problem. However, since I don't
know what else to do, I decide to try to fix this problem that I shouldn't
be having, and cast the values in the comparison like so:
DLOG("ppp_if: SIOC[GS]ETNPMODE cmd %x\n", i->ioc_cmd);
DLOG("ppp_if: Reference cmd %x\n", SIOCSETNPMODE);
if (((u_int32_t)i->ioc_cmd) == ((u_int32_t)SIOCSETNPMODE)) {
DLOG("ppp_if: SETNPMODE really is SETNPMODE!\n", 0);
Guess what? Now it works! I should be happy, but I'm not --- there's
something fundamental that's going on that I don't understand. Normally
when this happens I look at the assembly code to see what's REALLY going
on. I tried this, but being new to the Alpha, I don't really understand
it enough to see what was happening.
Does anybody have any ideas on what was happening? I'd be most grateful!
--
Steve Tate --- srt@cs.unt.edu | Conservatives: People who think that
Dept. of Computer Sciences | nothing should be done for the first
University of North Texas | time.
Denton, TX 76201 |
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Strange error in STREAMS code
1994-11-13 18:59 Strange error in STREAMS code Steve Tate
@ 1994-11-13 23:24 ` Steve Tate
1994-11-13 23:48 ` John Hascall
0 siblings, 1 reply; 7+ messages in thread
From: Steve Tate @ 1994-11-13 23:24 UTC (permalink / raw)
I'm following up on my own posting, because now I know WHAT is going
on, and it seems to me like the problem lies in the way things are
defined in the standard include files.
Here's the poop: The variable i->ioc_cmd is of type int, so gets
loaded into a 64-bit register with sign extension. The highest bit
is set in my example, so the high longword gets filled with ones. All
of the ioctl codes defined with _IOW(..) are of the form
(0x80000000 | .. | sizeof(.)), and the sizeof() operator makes this
whole constant expression actually to be of type long (maybe unsigned
long, I'm not sure.... but it is an 8 byte data type). Thus when
this value is used in a 64-bit register, it is NOT sign extended,
and the high longword is zero. Thus the equality test will always
be false.
Now ALL "write ioctl's" have the high bit set, and the ioctl codes
are defined through _IOW(..). Since this is the case, it doesn't
seem like an equality test will EVER succeed between an ioc_cmd
and an ioctl code (constant). Isn't this a fairly severe error
in the include file definitions? Shouldn't, for example, _IOW(..)
(or _IOC(..)) include a cast to type int? I am fixing my code
by casting ever single ioctl constant code to an int, but that
shouldn't really be unnecessary....
--
Steve Tate --- srt@cs.unt.edu | Conservatives: People who think that
Dept. of Computer Sciences | nothing should be done for the first
University of North Texas | time.
Denton, TX 76201 |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Strange error in STREAMS code
1994-11-13 23:24 ` Steve Tate
@ 1994-11-13 23:48 ` John Hascall
1994-11-14 16:34 ` Steve Tate
0 siblings, 1 reply; 7+ messages in thread
From: John Hascall @ 1994-11-13 23:48 UTC (permalink / raw)
Steve Tate <srt@zaphod.csci.unt.edu> wrote:
}Here's the poop: The variable i->ioc_cmd is of type int, so gets
}loaded into a 64-bit register with sign extension. The highest bit
}is set in my example, so the high longword gets filled with ones. All
}of the ioctl codes defined with _IOW(..) are of the form
}(0x80000000 | .. | sizeof(.)), and the sizeof() operator makes this
}whole constant expression actually to be of type long (maybe unsigned
}long, I'm not sure.... but it is an 8 byte data type). Thus when
}this value is used in a 64-bit register, it is NOT sign extended,
}and the high longword is zero. Thus the equality test will always
}be false.
From "man ioctl":
#include <sys/ioctl.h>
ioctl(
int d,
unsigned long request, <--- looks like it is intentional
char *argp ); that they are 64 bits.
I guess you should declare i->ioc_cmd as "unsigned long" too.
John
--
John Hascall ``An ill-chosen word is the fool's messenger.''
Systems Software Engineer, ISU Comp Center + Ames, IA 50011 + 515/294-9551
& Hascall Systems - Unix/C/Internet Consulting, Training, Custom Programming
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Strange error in STREAMS code
1994-11-13 23:48 ` John Hascall
@ 1994-11-14 16:34 ` Steve Tate
1994-11-14 19:13 ` John Hascall
1994-11-14 22:32 ` Charles M Richmond
0 siblings, 2 replies; 7+ messages in thread
From: Steve Tate @ 1994-11-14 16:34 UTC (permalink / raw)
John Hascall (john@iastate.edu) wrote:
> From "man ioctl":
> #include <sys/ioctl.h>
> ioctl(
> int d,
> unsigned long request, <--- looks like it is intentional
> char *argp ); that they are 64 bits.
Now isn't *THAT* interesting! Here's the prototype from
/usr/include/sys/ioctl.h:
extern int ioctl(int, int, ...);
So that directly contradicts the man page!!!!
> I guess you should declare i->ioc_cmd as "unsigned long" too.
I didn't declare ioc_cmd --- it's part of a standard structure (iocblk)
in /usr/include/sys/stream.h. That definition agrees with the prototype
for ioctl() in the standard header file, but neither agree with the
type of the constructed constants or with the man page.
Anyway, the only conclusion is that there are inconsistencies in the
way things are defines with respect to ioctl() --- does Digital have
a e-mail address for such bugs?
--
Steve Tate --- srt@cs.unt.edu | Conservatives: People who think that
Dept. of Computer Sciences | nothing should be done for the first
University of North Texas | time.
Denton, TX 76201 |
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Strange error in STREAMS code
1994-11-14 16:34 ` Steve Tate
@ 1994-11-14 19:13 ` John Hascall
1994-11-14 22:32 ` Charles M Richmond
1 sibling, 0 replies; 7+ messages in thread
From: John Hascall @ 1994-11-14 19:13 UTC (permalink / raw)
Steve Tate <srt@zaphod.csci.unt.edu> wrote:
}John Hascall (john@iastate.edu) wrote:
}
}> From "man ioctl":
}
}> #include <sys/ioctl.h>
}> ioctl(
}> int d,
}> unsigned long request, <--- looks like it is intentional
}> char *argp ); that they are 64 bits.
}
}Now isn't *THAT* interesting! Here's the prototype from
}/usr/include/sys/ioctl.h:
}
} extern int ioctl(int, int, ...);
}
}So that directly contradicts the man page!!!!
}
}> I guess you should declare i->ioc_cmd as "unsigned long" too.
}
}I didn't declare ioc_cmd --- it's part of a standard structure (iocblk)
}in /usr/include/sys/stream.h. That definition agrees with the prototype
}for ioctl() in the standard header file, but neither agree with the
}type of the constructed constants or with the man page.
Ah.
}Anyway, the only conclusion is that there are inconsistencies in the
}way things are defines with respect to ioctl() --- does Digital have
}a e-mail address for such bugs?
Yup. Looks like DEC botched this.
Seems to me that the only reasonable fix is for them to:
* amend the man page, and
* put a cast to int in the _IOC macro
(assuming this would be kosher with Posix, XPG, OSF, their mom, etc)
John
--
John Hascall ``An ill-chosen word is the fool's messenger.''
Systems Software Engineer, ISU Comp Center + Ames, IA 50011 + 515/294-9551
& Hascall Systems - Unix/C/Internet Consulting, Training, Custom Programming
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Strange error in STREAMS code
1994-11-14 16:34 ` Steve Tate
1994-11-14 19:13 ` John Hascall
@ 1994-11-14 22:32 ` Charles M Richmond
1994-11-15 4:00 ` John Hascall
1 sibling, 1 reply; 7+ messages in thread
From: Charles M Richmond @ 1994-11-14 22:32 UTC (permalink / raw)
srt@zaphod.csci.unt.edu (Steve Tate) writes:
>John Hascall (john@iastate.edu) wrote:
>> From "man ioctl":
>> #include <sys/ioctl.h>
>> ioctl(
>> int d,
>> unsigned long request, <--- looks like it is intentional
>> char *argp ); that they are 64 bits.
>Now isn't *THAT* interesting! Here's the prototype from
>/usr/include/sys/ioctl.h:
> extern int ioctl(int, int, ...);
>So that directly contradicts the man page!!!!
The man page is incorrect and I have filed a QAR to get it fixed.
Charlie
--
*****************************************************************************
* Charles Richmond Integrated International Systems Corporation *
* cmr@asoko.iisc.com cmr@world.std.com *
* Specializing in UNIX, X, Image Processing, and Communications. *
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Strange error in STREAMS code
1994-11-14 22:32 ` Charles M Richmond
@ 1994-11-15 4:00 ` John Hascall
0 siblings, 0 replies; 7+ messages in thread
From: John Hascall @ 1994-11-15 4:00 UTC (permalink / raw)
Charles M Richmond <cmr@world.std.com> wrote:
}srt@zaphod.csci.unt.edu (Steve Tate) writes:
}>John Hascall (john@iastate.edu) wrote:
}>> From "man ioctl":
}>> #include <sys/ioctl.h>
}>> ioctl(
}>> int d,
}>> unsigned long request, <--- looks like it is intentional
}>> char *argp ); that they are 64 bits.
}
}>Now isn't *THAT* interesting! Here's the prototype from
}>/usr/include/sys/ioctl.h:
}
}> extern int ioctl(int, int, ...);
}
}>So that directly contradicts the man page!!!!
}The man page is incorrect and I have filed a QAR to get it fixed.
Not only is the man page wrong, but so are the definitions of _IOR,
_IOW, & _IOWR (and hence all of the xIOCyyyy manifest constants); for
example:
#define _IOC(inout,group,num,len) \
(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
|
type is "size_t", which is
"unsigned long" on AXP-OSF/1
#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */
John
--
John Hascall ``An ill-chosen word is the fool's messenger.''
Systems Software Engineer, ISU Comp Center + Ames, IA 50011 + 515/294-9551
& Hascall Systems - Unix/C/Internet Consulting, Training, Custom Programming
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1994-11-15 4:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-11-13 18:59 Strange error in STREAMS code Steve Tate
1994-11-13 23:24 ` Steve Tate
1994-11-13 23:48 ` John Hascall
1994-11-14 16:34 ` Steve Tate
1994-11-14 19:13 ` John Hascall
1994-11-14 22:32 ` Charles M Richmond
1994-11-15 4:00 ` John Hascall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox