3.1 Glue code

As AmigaOS doesn't support the export of named symbols from library files, Hollywood plugins need to provide some glue code on AmigaOS and compatible systems so that Hollywood can locate symbols by name instead of by jumptable.

After calling LoadSeg() on your plugin, Hollywood will look for two magic cookies that must be embedded in the MagicCookie[] array in the following structure:

 
typedef struct _hwAmigaEntry
{
    ULONG MagicCookie[2];
    int Platform;
    void *(*GetProcAddress)(STRPTR name);
} hwAmigaEntry;

Thus, your plugin needs to declare a global constant based on this structure so that Hollywood can identify the file as a Hollywood plugin. An example declaration could be like this:

 
const hwAmigaEntry entry = {
    {HWPLUG_COOKIE1, HWPLUG_COOKIE2},
    HWARCH_OS3,
    GetProcAddress,
};

Make sure that the compiler doesn't optimize this declaration away just because it isn't referenced anywhere. Otherwise Hollywood won't be able to load your plugin. As you can see MagicCookie[] needs to be set to HWPLUG_COOKIE1 and HWPLUG_COOKIE2 which are both defined in hollywood/plugin.h. Note that different cookies are used on little endian systems so make sure to define the preprocessor constant HW_LITTLE_ENDIAN if you target little endian systems.

It is very important to set hwAmigaEntry.Platform to the correct architecture constant. In the above example we set it to HWARCH_OS3 indicating that this is a plugin for AmigaOS 3.

You can also see that the declaration above references a function named GetProcAddress(). You need to implement this function in your glue code as well. Hollywood calls this function whenever it needs to resolve a function pointer from a symbol name. Thus, your implementation of GetProcAddress() needs to look at the string argument it has received and then return the appropriate function pointer. This can be implemented using a lookup table like this:

 
static const struct
{
    STRPTR name;
    void *func;
} funcs[] =
{
    {"InitPlugin", (void *) InitPlugin},
    {"ClosePlugin", (void *) ClosePlugin},
    // ...more function pointers here, depending on plugin type
    {NULL, NULL}
};

HW_EXPORT void *GetProcAddress(STRPTR name)
{
    int k;

    for(k = 0; funcs[k].name; k++) {
        if(!strcmp(name, funcs[k].name)) return funcs[k].func;
    }

    return NULL;
}

Another speciality on AmigaOS is that you cannot use certain functions from the standard ANSI C runtime library. See AmigaOS C runtime limitations for details.


Show TOC