Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with lib$spawn when compiling with pointer_size=64

 
Not applicable

Problem with lib$spawn when compiling with pointer_size=64

Hi All,

Recently we have compiled our product with 64 bit when we found lib$spawn is not working properly with 64 bit pointer size.

I have written a small C program below to show the problem:

********************************************
TEST_LIBSPAWN.C
********************************************

void spawn_ast(int *);
void main()
{
$DESCRIPTOR64 ( command, "show time");
int *astprm, flags = CLI$M_NOWAIT;

astprm = (int *) malloc(sizeof(int));
*astprm = 10;

lib$spawn( &command, 0, 0, &flags, 0, 0, 0, 0 , &spawn_ast, (unsigned)astprm );
sleep(1);
}

void spawn_ast( int * astprm )
{
printf("%d\n\n",*astprm);
}

********************************************

When we compile and build the image as:

cc TEST_LIBSPAWN.C
link TEST_LIBSPAWN
run TEST_LIBSPAWN

everything works fine and the output is:

20-JAN-2009 12:09:26
10

But when I compile as pointer_size = 64 and run the image, it give some absurd value at the memory address being passed to lib$spawn at astprm:

cc TEST_LIBSPAWN.C /pointer_size=64
link TEST_LIBSPAWN
run TEST_LIBSPAWN

and the output is:

20-JAN-2009 12:10:52
538902529


Could anyone help me to know did i do anything wrong? and if not then why the value at address of "astprm" is getting changed from "10" to some absurd value "538902529".

Regards,
ajaydec
10 REPLIES 10
Joseph Huber_1
Honored Contributor

Re: Problem with lib$spawn when compiling with pointer_size=64

You are passing in the astparam argument an integer casted from a pointer. I just wonder why it results in the right value when compiled with 32 bit addresses.

Change all "int *" to "int" in the ast routine declarations, and
pass *astprm instead of (unsigned)astprm , and You will see what You want, namely the parameter value, not the truncated address.

If Your intention is really to pass an address as a parameter, then no, it is not possible with 64-bit pointers, since lib$spawn expects a longword by value in the astprm argument.

I see that help for lib$spawn mention "typically" the usage for passing a pointer, but should be updated to mention the 32-bit restriction.
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: Problem with lib$spawn when compiling with pointer_size=64

Ah sorry, I should not have wondered why it works with 32-bit pointers :-)
An unsigned integer of course can hold a full 32-bit address.
But the explanation for 64-bit pointers holds.
http://www.mpp.mpg.de/~huber
Not applicable

Re: Problem with lib$spawn when compiling with pointer_size=64

Hi Joseph,

Thanks a lot for your reply. My intention is to pass an address of a structure as a parameter. Since we can not pass 64-bit address is there any other means we can achieve it.

Regards,
ajaydec
Joseph Huber_1
Honored Contributor

Re: Problem with lib$spawn when compiling with pointer_size=64

As long lib$spawn is like that, no, I don't see a way to pass 64-bit items to the AST.

What You could do is to pass a 32-bit index in a global array of pointer to structures.
Or, if the number of such structures cannot be limited to a maximum, build a linked list of (identifier,pointer), pointer to the list-head in a global variable, and pass the identifier to the AST.
http://www.mpp.mpg.de/~huber
Martin Vorlaender
Honored Contributor

Re: Problem with lib$spawn when compiling with pointer_size=64

Ajaydec,

you can explicitly use the _malloc32 routine to request a 32-bit address for the AST parameter.

cu,
Martin