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

Invalid arguments with sys$mgblsc on VMS 7.3-2 Alpha

Go to solution
dead user_2
Occasional Visitor

Invalid arguments with sys$mgblsc on VMS 7.3-2 Alpha

I am trying to map a section of my program memory to a global section created by another process. I can map it to my process memory and then read and modify it, but if I try to map to a specific common section I have set up I get a 4042 error.

What can I do to fix this?
John Gillings
Honored Contributor

Re: Invalid arguments with sys$mgblsc on VMS 7.3-2 Alpha


On Alpha global sections are always whole numbers of physical pages. The INADDR argument must be precise - first address is on a page boundary (which you've done correctly by aligning your data), end address must be the last byte on the last page of the section. Note these are Alpha system pages, so 8KB. Although I haven't done the calculation, I'm fairly certain your endcommon address doesn't satisfy this requirement.

Try changing your code to something like:

in_addr(2) = (((%loc(endcommon)+SYI$_PAGE_SIZE).AND..NOT.(SYI$_PAGE_SIZE-1))-1

So, first we add the size of a page to the end address, then mask off the low bits, this gives the start address of the next page beyond endcommon, then we subtract 1 to give the address of the last byte of the page containing endcommon. The calculation is correct even if endcommon is already the last byte on a page.

That said, it probably makes sense to pad your common block out to a whole number of pages. You don't know what variables may be mapped to the extra locations beyond your common block. Consider, what if you have two processes map to this global section, each of which has their own private variables just beyond the common block. Suddenly they're global, overmapping variables in other processes. Modifications in one process will automagically show up as completely unrelated variables in the other process. Impossible to reproduce exactly, and very difficult to debug.

The call "works" with EXPREG because that causes the INADDR argument to be ignored. The section is mapped to the next available virtual page(s) in P0 space. In your case, the section is mapped, but not where you wanted it.

When using $CRMPSC or $MGBLSC, always check the RETADR argument as well as the return status to make sure it really did exactly what you wanted (at least while debugging).
A crucible of informative mistakes
Ian Miller.
Honored Contributor

Re: Invalid arguments with sys$mgblsc on VMS 7.3-2 Alpha

See also the fine documentation

Generally using EXPREG is better but how you would refer to this in the programming language you are using I know not.
Purely Personal Opinion
dead user_2
Occasional Visitor

Re: Invalid arguments with sys$mgblsc on VMS 7.3-2 Alpha

Adjusting the in_addr(2) to the correct page boundary fixed the problem. Thanks very much.