SLB(5) Programmer's Manual SLB(5) *NAME* SLB shared library file format *DESCRIPTION* A SLB shared library is a normal GEMDOS executable with a specific start of the text segment: typedef { long magic; #define SLB_MAGIC 0x70004afcL char *name; long version; long flags; void (*slb_init) (void); void (*slb_exit) (void); void (*slb_open) (BASPAG *); void (*slb_close) (BASPAG *); long opt; long res[8]; long fun_cnt; long fun_table[]; } SLB; It is recommended that bit 3 of byte 25 of the program header is set to indicate that the module can be loaded into a TPA of "any sufficient" size. This is required for MagiC to shrink the shared library to minimal size after loading, and it will also help preventing memory fragmentation, see *runopts(1)* for a description of existing program flags. *runopts(1)* is available from http://www.muenster.de/~reschke/soft_e.hmtl#mupftool. magic must be the first four octets of the text segment and be equal to *SLB_MAGIC.* name is a pointer (relative to the start of the text segment) to a C style string with the name of the shared library. version is the version number of the shared library (see *Slbopen(2)* ). flags is reserved and must be set to 0 for now. slb_init is a pointer to the init function of the shared library. This function gets called once when the library is initially loaded and is executed under the context of the shared library (MagiC, FreeMiNT) or the Atari TOS Release: 1999-12-27 Page 1 SLB(5) Programmer's Manual SLB(5) first caller's program (MetaDOS). Depending on the environment, this call will be executed in supervisor mode (MagiC, MetaDOS) or use mode (FreeMiNT). The path name of the shared library file is passed in the command line area of the SLB's basepage. Contrary to a GEMDOS process, the string is in C format (no in- itial length byte, zero terminated). An SLB can use this information to find additional files in the direc- tory from where the SLB was loaded. Note that this file name might contain a relative path and thus needs to be evaluated during slb_init. slb_exit is a pointer to the exit function of the shared library. It gets called before the shared library is unloaded from memory (because the last owner has closed it) and is executed under the context of the shared library (MagiC, FreeMiNT) or the first caller's program (MetaDOS). Depending on the environment, this call will be executed in supervisor mode (MagiC, MetaDOS) or use mode (FreeMiNT). slb_open points to the SLB open function. It gets called everytime a process opens the shared library. A pointer to the caller's basepage is passed on the stack. Depending on the operating system, this call will be executed in supervisor mode (MetaDOS) or user mode (MagiC, FreeMiNT). slb_close points to the SLB close function. It gets called everytime a process closes the shared library (or ter- mininates without explicitly closing it). A pointer to the caller's basepage is passed on the stack. Depending on the operating system, this call will be executed in supervisor mode (MetaDOS) or user mode (MagiC, FreeMiNT). opt is reserved. res[] is reserved. fun_cnt is the total number of library function pointers. It is used to do a sanity check on the number argument when the shared library is called. fun_table[] is an array with the pointers to the individual shared library functions, starting with function 0. Note that a function pointer may be zero, in which case the library Atari TOS Release: 1999-12-27 Page 2 SLB(5) Programmer's Manual SLB(5) exec function will return EINVFN. Shared library functions will receive parameters exactly in the way the caller passed them. The only difference is that the library function will receive a pointer to the caller's BASEPAGE instead of the SLB pointer as first argument. *CAVEAT* Note that under plain TOS, the same restrictions apply for shared library usage as for GEMDOS allocated memory or file handles: accessories aren't real GEMDOS processes, the ownership thus belongs to the currently running GEMDOS process. Loaded shared libraries appear as separate entries in u:\proc both under MagiC and FreeMiNT (in this case as a stopped process), but so far no attempt has been made to synchronize the implementation (process flags and possible new Fcntl() opcodes). *BUGS* The command line area of the basepage is limited to 128 bytes, thus the name of the SLB file needs to fit into 127 characters. Users should have a method to find out which SLB is required by which executable, and there should also be a way to find out which executables are using an SLB which is currently loaded. The latter could be implemented through new Fcntl() opcodes on the process entry. For the former issue, I recommend to add an RCS ident string for each required SLB file, with the following format: $slb: filename, revision information$ For instance: $slb: dosix001.slb, rev 1, Dec 4 1999$ *SEE ALSO* ident(1), runopts(1), Slbopen(2) Atari TOS Release: 1999-12-27 Page 3