develooper Front page | perl.perl5.porters | Postings from January 2006

Arguments of syscall()

Thread Previous | Thread Next
From:
Dintelmann, Peter
Date:
January 26, 2006 00:20
Subject:
Arguments of syscall()
Message ID:
E9A2605289D8D7468B1A21EC24E59D21049792E9@naimucx5.muc.allianz
Playing around with syscall() on Solaris with both a 32-bit and
a 64-bit Perl installation I had a look at pp_sys.c and noticed
that the arguments are always passed as unsigned longs:

    unsigned long a[20];
    ... ... ...

    /* This probably won't work on machines where sizeof(long) !=
sizeof(int)
     * or where sizeof(long) != sizeof(char*).  But such machines will
     * not likely have syscall implemented either, so who cares?
     */
    while (++MARK <= SP) {
	if (SvNIOK(*MARK) || !i)
	    a[i++] = SvIV(*MARK);
	else if (*MARK == &PL_sv_undef)
	    a[i++] = 0;
	else
	    a[i++] = (unsigned long)SvPV_force_nolen(*MARK);
	if (i > 15)
	    break;
    }
    switch (items) {
    ... ... ...
    case 2:
	retval = syscall(a[0],a[1]);
	break;
    ... ... ...

The comment implies from my perspective that the unsigned long type
may not be appropriate in all situations. The following patch tries
to mitigate this by using the PTRV type instead.

    $ diff -ur pp_sys.c.ori pp_sys.c
    --- pp_sys.c.ori        Wed Jan 25 12:59:18 2006
    +++ pp_sys.c    Wed Jan 25 13:00:28 2006
    @@ -5579,7 +5579,7 @@
     #ifdef HAS_SYSCALL
         dSP; dMARK; dORIGMARK; dTARGET;
         register I32 items = SP - MARK;
    -    unsigned long a[20];
    +    PTRV a[20];
         register I32 i = 0;
         I32 retval = -1;
         STRLEN n_a;
    @@ -5601,11 +5601,11 @@
          */
         while (++MARK <= SP) {
            if (SvNIOK(*MARK) || !i)
    -           a[i++] = SvIV(*MARK);
    +           a[i++] = INT2PTR(PTRV, SvIV(*MARK));
            else if (*MARK == &PL_sv_undef)
                a[i++] = 0;
            else
    -           a[i++] = (unsigned long)SvPV_force(*MARK, n_a);
    +           a[i++] = INT2PTR(PTRV, SvPV_force(*MARK, n_a));
            if (i > 15)
                break;
         }

On my Solaris system this successfully runs with both (32/64-bit)
Perl installations.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About