PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

SetDriverClosureMemory

OSErr SetDriverClosureMemory(
                     CFragConnectionID fragmentConnID,
                     Boolean holdDriverMemory);
fragmentConnID
ID of driver closure (returned from other DLL loading services).
holdDriverMemory
Pass true to hold a driver closure; false to free it.
DESCRIPTION

A driver and all its libraries is called a driver closure. When a driver is loaded and prepared for initialization by the DLL, memory for its closure is held as the final step in implementing GetDriverMemoryFragment and GetDriverDiskFragment. Closure memory is held by default to prevent page faults at primary and secondary interrupt level.

SetDriverClosureMemory lets you hold closure memory by setting the holdDriverMemory parameter to true. It can also be use to free memory held (unhold) for a driver closure by setting the holdDriverMemory parameter to false.

To undo the effects of GetDriverMemoryFragment or GetDriverDiskFragment, an I/O expert can call SetDriverMemoryClosureMemory (cfmID, false) followed by CloseConnection (&cfmID). This has the effect of unloading the driver. Listing 9-2 shows a sample of code to perform this task.

Listing 9-2 Unloading a driver

void UnloadTheDriver ( CFragConnectionID fragID )
{
    OSErr       Status;
    THz         theCurrentZone          = GetZone();

    // make sure the fragment is attached to the system context
    // (CFM keys context from the current heap zone)
    SetZone ( SystemZone() );

    Status = SetDriverClosureMemory (fragID,false);
    if ( Status != noErr )
     printf("Couldn't unhold pages of Driver Closure!
                (Err==%x)\n",Status);

    Status = CloseConnection(&fragID);
    if ( Status != noErr )
     printf("Couldn't close Driver Connection!
                (Err==%x)\n",Status);

    // reset the zone
    SetZone ( theCurrentZone );
}

Note that you must switch the current heap to the system heap before calling CloseConnection.


© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)