Arne Vajhøj
2025-01-08 01:58:29 UTC
During some troubleshooting over at VSI forum hb told me that
running a shareable image will execute LIB$INITIALIZE
functions.
That made me write this:
$ type lib.pas
[inherit('sys$library:pascal$lib_routines', 'sys$library:starlet')]
module lib(input, output);
[global]
procedure check;
var
imgnam : varying [1024] of char;
begin
lib$getjpi(item_code := jpi$_imagname, resultant_string :=
imgnam.body, resultant_length := imgnam.length);
if index(imgnam, ']libshr.EXE') > 0 then begin
writeln('This is a shareable image to link against not run');
$exit(ss$_normal);
end;
end;
[global]
procedure say;
begin
writeln('Hi');
end;
end.
$ type prg.pas
program prg(input,output);
[external]
procedure say; external;
begin
say;
end.
$ type trick.mar
.title trick
.extrn lib$initialize
.psect lib$initialize long,nopic,con,gbl,noshr,noexe,nowrt
.address check
.end
$ macro trick
$ pas lib
$ link/share=libshr lib + trick + sys$input/opt
SYMBOL_VECTOR=(say=PROCEDURE)
$
$ define/nolog libshr sys$disk:[]libshr
$ pas prg
$ link prg + sys$input/opt
libshr/share
$
$ run prg
Hi
$ run libshr
This is a shareable image to link against not run
:-)
Arne
running a shareable image will execute LIB$INITIALIZE
functions.
That made me write this:
$ type lib.pas
[inherit('sys$library:pascal$lib_routines', 'sys$library:starlet')]
module lib(input, output);
[global]
procedure check;
var
imgnam : varying [1024] of char;
begin
lib$getjpi(item_code := jpi$_imagname, resultant_string :=
imgnam.body, resultant_length := imgnam.length);
if index(imgnam, ']libshr.EXE') > 0 then begin
writeln('This is a shareable image to link against not run');
$exit(ss$_normal);
end;
end;
[global]
procedure say;
begin
writeln('Hi');
end;
end.
$ type prg.pas
program prg(input,output);
[external]
procedure say; external;
begin
say;
end.
$ type trick.mar
.title trick
.extrn lib$initialize
.psect lib$initialize long,nopic,con,gbl,noshr,noexe,nowrt
.address check
.end
$ macro trick
$ pas lib
$ link/share=libshr lib + trick + sys$input/opt
SYMBOL_VECTOR=(say=PROCEDURE)
$
$ define/nolog libshr sys$disk:[]libshr
$ pas prg
$ link prg + sys$input/opt
libshr/share
$
$ run prg
Hi
$ run libshr
This is a shareable image to link against not run
:-)
Arne