public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] x86 compatability problem: ioctl() SIOCGIFCONF
@ 2002-02-20 17:03 Tseng-hui Lin
  2002-02-20 17:21 ` n0ano
  2002-02-21  6:59 ` Don Dugger
  0 siblings, 2 replies; 3+ messages in thread
From: Tseng-hui Lin @ 2002-02-20 17:03 UTC (permalink / raw)
  To: linux-ia64

    I need to keep some x86 code alive in IA64 land. It looks like ioctl()
SIOCGIFCONF function doesn't work. I compiled the attached test program on
an x86 machine and ran it on an RedHat 7.2 Linux/IA64. It gave me "ioctl
SIOCGIFCONF: Bad address". The program works if it is compiled and run on
an IA64 machine. I know that the sizes of struct ifreq are different on x86
and IA64. However, it hasn't reached that part yet. I thought it might be
memory alignment problem since ioctl() returns "Bad address". I put some
paddings to make the variables allocated on 8-byte boundary but the problem
is still there. Has any one seen this problem before?

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>

#define MAX_NUM_IFREQ (512)

main() {
    struct ifconf       Ifc;
    struct ifreq        IfcBuf[MAX_NUM_IFREQ];
    struct ifreq        *pIfr;
    int num_ifreq;
    int i;
    int fd;

    Ifc.ifc_len = sizeof(IfcBuf);
    Ifc.ifc_buf = (char *) IfcBuf;

    if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        perror("socket()");
        exit(1);
    }
    if ( ioctl(fd, SIOCGIFCONF, &Ifc) < 0) {
        perror("ioctl SIOCGIFCONF");
        exit(1);
    }
    num_ifreq = Ifc.ifc_len / sizeof(struct ifreq);
    for ( pIfr = Ifc.ifc_req, i = 0 ; i < num_ifreq; pIfr++, i++ ) {
        printf("%d: %s<=\n", i, pIfr->ifr_name);
    }
}

Tseng-Hui (Frank) Lin  tsenglin@us.ibm.com
Phone:(512)838-8312  T/L 678-8312
FAX: (512)838-3484 T/L 678-3484
IBM Poughkeepsie Unix Development Lab, Dept XXWA
Building 905-2H018, 11501 Burnet Road, Austin, TX 78758



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-ia64] x86 compatability problem: ioctl() SIOCGIFCONF
  2002-02-20 17:03 [Linux-ia64] x86 compatability problem: ioctl() SIOCGIFCONF Tseng-hui Lin
@ 2002-02-20 17:21 ` n0ano
  2002-02-21  6:59 ` Don Dugger
  1 sibling, 0 replies; 3+ messages in thread
From: n0ano @ 2002-02-20 17:21 UTC (permalink / raw)
  To: linux-ia64

Frank-

Support for IA32 `ioctl's is a hard problem, most have to be dealt
with on a case by case basis.  This is just one that got missed.
This one shouldn't be to difficult, give me a day or two and I
should be able to send out a patch to fix it.

On Wed, Feb 20, 2002 at 11:03:51AM -0600, Tseng-hui Lin wrote:
>     I need to keep some x86 code alive in IA64 land. It looks like ioctl()
> SIOCGIFCONF function doesn't work. I compiled the attached test program on
> an x86 machine and ran it on an RedHat 7.2 Linux/IA64. It gave me "ioctl
> SIOCGIFCONF: Bad address". The program works if it is compiled and run on
> an IA64 machine. I know that the sizes of struct ifreq are different on x86
> and IA64. However, it hasn't reached that part yet. I thought it might be
> memory alignment problem since ioctl() returns "Bad address". I put some
> paddings to make the variables allocated on 8-byte boundary but the problem
> is still there. Has any one seen this problem before?
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/ioctl.h>
> #include <sys/socket.h>
> #include <net/if.h>
> 
> #define MAX_NUM_IFREQ (512)
> 
> main() {
>     struct ifconf       Ifc;
>     struct ifreq        IfcBuf[MAX_NUM_IFREQ];
>     struct ifreq        *pIfr;
>     int num_ifreq;
>     int i;
>     int fd;
> 
>     Ifc.ifc_len = sizeof(IfcBuf);
>     Ifc.ifc_buf = (char *) IfcBuf;
> 
>     if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
>         perror("socket()");
>         exit(1);
>     }
>     if ( ioctl(fd, SIOCGIFCONF, &Ifc) < 0) {
>         perror("ioctl SIOCGIFCONF");
>         exit(1);
>     }
>     num_ifreq = Ifc.ifc_len / sizeof(struct ifreq);
>     for ( pIfr = Ifc.ifc_req, i = 0 ; i < num_ifreq; pIfr++, i++ ) {
>         printf("%d: %s<=\n", i, pIfr->ifr_name);
>     }
> }
> 
> Tseng-Hui (Frank) Lin  tsenglin@us.ibm.com
> Phone:(512)838-8312  T/L 678-8312
> FAX: (512)838-3484 T/L 678-3484
> IBM Poughkeepsie Unix Development Lab, Dept XXWA
> Building 905-2H018, 11501 Burnet Road, Austin, TX 78758
> 
> 
> _______________________________________________
> Linux-IA64 mailing list
> Linux-IA64@linuxia64.org
> http://lists.linuxia64.org/lists/listinfo/linux-ia64

-- 
Don Dugger
"Censeo Toto nos in Kansa esse decisse." - D. Gale
n0ano@indstorage.com
Ph: 303/652-0870x117


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-ia64] x86 compatability problem: ioctl() SIOCGIFCONF
  2002-02-20 17:03 [Linux-ia64] x86 compatability problem: ioctl() SIOCGIFCONF Tseng-hui Lin
  2002-02-20 17:21 ` n0ano
@ 2002-02-21  6:59 ` Don Dugger
  1 sibling, 0 replies; 3+ messages in thread
From: Don Dugger @ 2002-02-21  6:59 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 2220 bytes --]

Frank-

OK, here's a patch that should solve your problem.  It's a little
uglier than I'd like but there's not much I can do about that, at
least it works.

On Wed, Feb 20, 2002 at 11:03:51AM -0600, Tseng-hui Lin wrote:
>     I need to keep some x86 code alive in IA64 land. It looks like ioctl()
> SIOCGIFCONF function doesn't work. I compiled the attached test program on
> an x86 machine and ran it on an RedHat 7.2 Linux/IA64. It gave me "ioctl
> SIOCGIFCONF: Bad address". The program works if it is compiled and run on
> an IA64 machine. I know that the sizes of struct ifreq are different on x86
> and IA64. However, it hasn't reached that part yet. I thought it might be
> memory alignment problem since ioctl() returns "Bad address". I put some
> paddings to make the variables allocated on 8-byte boundary but the problem
> is still there. Has any one seen this problem before?
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/ioctl.h>
> #include <sys/socket.h>
> #include <net/if.h>
> 
> #define MAX_NUM_IFREQ (512)
> 
> main() {
>     struct ifconf       Ifc;
>     struct ifreq        IfcBuf[MAX_NUM_IFREQ];
>     struct ifreq        *pIfr;
>     int num_ifreq;
>     int i;
>     int fd;
> 
>     Ifc.ifc_len = sizeof(IfcBuf);
>     Ifc.ifc_buf = (char *) IfcBuf;
> 
>     if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
>         perror("socket()");
>         exit(1);
>     }
>     if ( ioctl(fd, SIOCGIFCONF, &Ifc) < 0) {
>         perror("ioctl SIOCGIFCONF");
>         exit(1);
>     }
>     num_ifreq = Ifc.ifc_len / sizeof(struct ifreq);
>     for ( pIfr = Ifc.ifc_req, i = 0 ; i < num_ifreq; pIfr++, i++ ) {
>         printf("%d: %s<=\n", i, pIfr->ifr_name);
>     }
> }
> 
> Tseng-Hui (Frank) Lin  tsenglin@us.ibm.com
> Phone:(512)838-8312  T/L 678-8312
> FAX: (512)838-3484 T/L 678-3484
> IBM Poughkeepsie Unix Development Lab, Dept XXWA
> Building 905-2H018, 11501 Burnet Road, Austin, TX 78758
> 
> 
> _______________________________________________
> Linux-IA64 mailing list
> Linux-IA64@linuxia64.org
> http://lists.linuxia64.org/lists/listinfo/linux-ia64

-- 
Don Dugger
"Censeo Toto nos in Kansa esse decisse." - D. Gale
n0ano@n0ano.com
Ph: 303/449-0877

[-- Attachment #2: patch_0221.l --]
[-- Type: text/plain, Size: 1187 bytes --]

--- kernel-bigsur-ref/arch/ia64/ia32/ia32_ioctl.c	Fri Nov  9 15:26:17 2001
+++ kernel-bigsur/arch/ia64/ia32/ia32_ioctl.c	Thu Feb 21 00:06:57 2002
@@ -79,6 +79,38 @@
 
 		      return ret;
 	      }
+		case IOCTL_NR(SIOCGIFCONF):
+		{
+			struct ifconf32 {
+				int		ifc_len;
+				unsigned int	ifc_ptr;
+			} ifconf32;
+			struct ifconf ifconf;
+			int i, n;
+			char *p32, *p64;
+			char buf[32];	/* sizeof IA32 ifreq structure */
+
+			if (copy_from_user(&ifconf32, P(arg), sizeof(ifconf32)))
+				return -EFAULT;
+			ifconf.ifc_len = ifconf32.ifc_len;
+			ifconf.ifc_req = P(ifconf32.ifc_ptr);
+			ret = DO_IOCTL(fd, SIOCGIFCONF, &ifconf);
+			ifconf32.ifc_len = ifconf.ifc_len;
+			if (copy_to_user(P(arg), &ifconf32, sizeof(ifconf32)))
+				return -EFAULT;
+			n = ifconf.ifc_len / sizeof(struct ifreq);
+			p32 = P(ifconf32.ifc_ptr);
+			p64 = P(ifconf32.ifc_ptr);
+			for (i = 0; i < n; i++) {
+				if (copy_from_user(buf, p64, sizeof(struct ifreq)))
+					return -EFAULT;
+				if (copy_to_user(p32, buf, sizeof(buf)))
+					return -EFAULT;
+				p32 += sizeof(buf);
+				p64 += sizeof(struct ifreq);
+			}
+			return ret;
+		}
 
 	      case IOCTL_NR(DRM_IOCTL_VERSION):
 	      {

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-21  6:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-20 17:03 [Linux-ia64] x86 compatability problem: ioctl() SIOCGIFCONF Tseng-hui Lin
2002-02-20 17:21 ` n0ano
2002-02-21  6:59 ` Don Dugger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox