Exemple #1
0
void __asm __saveds intAHIsub_FreeAudio(
    register __a2 struct AHIAudioCtrlDrv *AudioCtrl )
{
  if(AudioCtrl->ahiac_DriverData)
  {
    FreeAslRequest(dd->fs_FileReq);
    FreeAslRequest(dd->fs_RecFileReq);
    FreeSignal(dd->fs_MasterSignal);
    FreeSignal(dd->fs_RecMasterSignal);
    FreeVec(AudioCtrl->ahiac_DriverData);
    AudioCtrl->ahiac_DriverData = NULL;
  }
}
Exemple #2
0
	AROS_LIBFUNC_INIT
#else
void FbxCleanupFS(
	REG(a0, struct FbxFS * fs),
	REG(a6, struct FileSysBoxBase *libBase))
{
#endif
	ADEBUGF("FbxCleanupFS(%#p)\n", fs);

	if (fs != NULL) {
		struct Library *SysBase = fs->sysbase;
		struct MinNode *chain;

		// clear msgport in device node.
		if (fs->devnode != NULL) fs->devnode->dn_Task = NULL;

		// doslist process
		if (fs->dlproc_port != NULL) {
			ObtainSemaphore(&libBase->dlproc_sem);
			if (--libBase->dlproc_refcount == 0)
				Signal(&libBase->dlproc->pr_Task, SIGBREAKF_CTRL_C);
			ReleaseSemaphore(&libBase->dlproc_sem);
		}

		while ((chain = (struct MinNode *)RemHead((struct List *)&fs->timercallbacklist)) != NULL) {
			FreeFbxTimerCallbackData(fs, FSTIMERCALLBACKDATAFROMFSCHAIN(chain));
		}

		if (fs->fsflags & FBXF_ENABLE_DISK_CHANGE_DETECTION) {
			FbxRemDiskChangeHandler(fs);
		}

		DeleteMsgPort(fs->fsport);
		DeleteMsgPort(fs->notifyreplyport);

		FreeSignal(fs->diskchangesig);
		FreeSignal(fs->dbgflagssig);

		DeletePool(fs->mempool);

		FbxCleanupTimerIO(fs);

		FreeFbxFS(fs);
	}

	ADEBUGF("FbxCleanupFS: DONE\n");

#ifdef __AROS__
	AROS_LIBFUNC_EXIT
#endif
}
Exemple #3
0
void dotimer(ULONG unit,ULONG timercmd,struct timeval *t)
{
    struct PortIO {
        struct timerequest treq;
        struct MsgPort port;
    } *portio;

    if ((portio = lib_AllocMem(sizeof(*portio), MEMF_CLEAR | MEMF_PUBLIC))) {
        portio->port.mp_Node.ln_Type = NT_MSGPORT;
        if ((BYTE)(portio->port.mp_SigBit = AllocSignal(-1)) >= 0) {
            portio->port.mp_SigTask = FindTask(NULL);
            NEWLIST(&portio->port.mp_MsgList);
            portio->treq.tr_node.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
            portio->treq.tr_node.io_Message.mn_ReplyPort = &portio->port;
            if (!(OpenDevice(TIMERNAME, unit, &portio->treq.tr_node, 0))) {
                portio->treq.tr_node.io_Command = timercmd;
                portio->treq.tr_time.tv_secs = t->tv_secs;
                portio->treq.tr_time.tv_micro = t->tv_micro;
                if (!DoIO(&portio->treq.tr_node)) {
                    t->tv_secs = portio->treq.tr_time.tv_secs;
                    t->tv_micro = portio->treq.tr_time.tv_micro;
                }
                CloseDevice(&portio->treq.tr_node);
            }
            FreeSignal(portio->port.mp_SigBit);
        }
        lib_FreeMem(portio,sizeof(struct PortIO));
    }
}
Exemple #4
0
static void
ExpungeUnit ( struct AHIDevUnit *iounit,
              struct AHIBase *AHIBase )
{
    struct Task *unittask;
    BYTE signal;

    signal = AllocSignal(-1);
    if(signal == -1)
    {
        /* Fallback */
        signal = SIGB_SINGLE;
        SetSignal(0, SIGF_SINGLE);
    }

    unittask = (struct Task *) iounit->Process;
    iounit->Process = (struct Process *) FindTask(NULL);
    iounit->SyncSignal = signal;
    Signal(unittask,SIGBREAKF_CTRL_F);
    Wait(1UL << signal);
    AHIBase->ahib_DevUnits[iounit->UnitNum]=NULL;
    FreeVec(iounit->Voices);
    FreeVec(iounit);

    if(signal != SIGB_SINGLE)
    {
        FreeSignal(signal);
    }
}
Exemple #5
0
VOID DeletePort(struct MsgPort *port)
{   APTR SysBase = *(APTR *)4L;

    if (port->mp_Node.ln_Name)
        RemPort(port);
    FreeSignal(port->mp_SigBit);
    FreeMem(port,sizeof(*port));
}
Exemple #6
0
void lib_DeleteMsgPort(SysBase *SysBase, struct MsgPort *msgPort)
{
	if (NULL != msgPort)
  	{
    	FreeSignal(msgPort->mp_SigBit);
    	FreeVec(msgPort);
  	}
}
Exemple #7
0
void _AHIsub_FreeAudio(
  struct AHIAudioCtrlDrv *AudioCtrl,
  struct DriverBase*      AHIsubBase )
  
{
  struct FilesaveBase* FilesaveBase = (struct FilesaveBase*) AHIsubBase;

  if(AudioCtrl->ahiac_DriverData)
  {
    FreeAslRequest(dd->fs_FileReq);
    FreeAslRequest(dd->fs_RecFileReq);
    FreeSignal(dd->fs_MasterSignal);
    FreeSignal(dd->fs_RecMasterSignal);
    FreeVec(AudioCtrl->ahiac_DriverData);
    AudioCtrl->ahiac_DriverData = NULL;
  }
}
Exemple #8
0
void AtaTaskFini (void)
{
	if (ata_isr14_enabled == TRUE)
	{
		ISRHandlerRemove (ata_isr14_handler);
		FreeSignal (ata_isr14_signal);
	}
	
	if (ata_isr15_enabled == TRUE)
	{
		ISRHandlerRemove (ata_isr15_handler);
		FreeSignal (ata_isr15_signal);
	}	
			
	DeleteMsgPort (ata_msgport);
	FreeSignal (ata_alarm_signal);
	Exit (0);
}
Exemple #9
0
static LONG open_con(struct conbase *conbase, struct IOFileSys *iofs)
{
    struct filehandle 	    *fh = (struct filehandle *)iofs->IOFS.io_Unit;
    STRPTR  	    	    filename = iofs->io_Union.io_OPEN.io_Filename;
#if DEBUG
    ULONG   	    	    mode = iofs->io_Union.io_OPEN.io_FileMode;
#endif
    struct conTaskParams    params;
    struct Task     	    *contask;
    LONG    	    	    err = 0;

    EnterFunc(bug("open_conh(filename=%s, mode=%d)\n",
    	filename, mode));

    /* we're a console, we don't have a parent */
    if (filename[0] == '/' && filename[1] == '\0')
        err = iofs->io_DosError = ERROR_OBJECT_NOT_FOUND;

    else if (fh != NULL && fh != (struct filehandle *)1)
    {
        /* DupLock */
	fh->usecount++;
    }
    
    else
    {
    	UBYTE sig = AllocSignal(-1);
	
	if (sig == (UBYTE)-1)
	{
	    iofs->io_DosError = ERROR_NO_FREE_STORE; /* Any other error code better suited here? */
	}
	else
	{
	    params.conbase = conbase;
	    params.iofs = iofs;
	    params.parentTask = FindTask(NULL);
	    params.initSignal = 1L << sig;

	    contask = createConTask(&params, conbase);
	    if (contask)
	    {
		Wait(params.initSignal);
		if (iofs->io_DosError)
		{
	    	    RemTask(contask);
		}
	    }
	    
	    FreeSignal(sig);
	}	
	err = iofs->io_DosError;
    }

    ReturnInt("open_conh", LONG, err);
}
Exemple #10
0
VOID ClosePort (struct MsgPort *mp,
    struct IFFParseBase_intern * IFFParseBase)
{
    mp->mp_SigTask	    =  (struct Task*)-1;
    mp->mp_MsgList.lh_Head  = (struct Node*)-1;

    FreeSignal( mp->mp_SigBit );

    return;
}
Exemple #11
0
__saveds void ErrorProcess(void)
{
	char constring[200];
	BPTR file=NULL;
	ULONG sig;
	ULONG lock;
	ErrorSig=AllocSignal(ErrorSig);
	hassent=1;
	errorprocessalive=1;
	ErrorTask=FindTask(NULL);

	sprintf(constring,"CON:%d/%d/%d/%d/%s/SCREEN%s",20,20,500,300,"radium.nfo",screenname);

	for(;;){
		sig=Wait(1L<<ErrorSig|SIGBREAKF_CTRL_C);
		if(sig&1L<<ErrorSig){
			if(file==NULL){
				file=Open(constring,0x3ee);
			}
			if(file!=NULL && errorwindow==NULL){
				if(mainscreen!=NULL){
					struct Window *tempwindow;
					lock=LockIBase(0);
						tempwindow=mainscreen->FirstWindow;
						for(;;){
							if(tempwindow==NULL) break;
							if(!strcmp(tempwindow->Title,"radium.nfo")){
								errorwindow=tempwindow;
								break;
							}
							tempwindow=tempwindow->NextWindow;
						}
					UnlockIBase(lock);
 				}
			}

			if(file==NULL){
				fprintf(stderr,errorstring);
			}else{
				FPuts(file,errorstring);
			}
			hassent=1;

			if(errorwindow!=NULL){
				WindowToFront(errorwindow);
			}
		}
		if(sig&SIGBREAKF_CTRL_C) break;
	}

	if(file!=NULL){
		Close(file);
	}
	FreeSignal(ErrorSig);
}
Exemple #12
0
VOID Init_LinuxInput_inputtask(struct EventHandler * eh)
{
    struct inputtask_params p;
    p.ok_signal = AllocSignal(-1L);
    p.nok_signal = AllocSignal(-1L);
    p.eh = eh;
    p.creator = FindTask(NULL);

    D(bug("init_input_task: p.lsd = %p, p.creator = %p\n", p.lsd, p.creator));
    
    D(bug("SIGNALS ALLOCATED\n"));
    
    eh->inputtask = create_inputtask(&p);
    
    D(bug("INPUTTASK CREATED\n"));

    /* No need for these anymore */
    FreeSignal(p.ok_signal);
    FreeSignal(p.nok_signal);
}
Exemple #13
0
void DeletePort (struct MsgPort *port)
{
    int i;

    if (port->mp_Node.ln_Name != NULL)
	RemPort (port);
    i = -1;
    port->mp_Node.ln_Type = i;
    port->mp_MsgList.lh_Head = (struct Node *)i;
    FreeSignal (port->mp_SigBit);
    PPCFreeMem (port, sizeof (struct MsgPort));
}
Exemple #14
0
struct Task *init_linuxinput_task(struct linux_staticdata *lsd)
{
    struct inputtask_params p;
    p.ok_signal = AllocSignal(-1L);
    p.fail_signal = AllocSignal(-1L);
    p.kill_signal = SIGBREAKF_CTRL_C;
    p.lsd = lsd;
    p.parent = FindTask(NULL);

kprintf("init_input_task: p.lsd = %p\n", p.lsd);
    
    kprintf("SIGNALS ALLOCATED\n");
    
    lsd->input_task = create_inputtask(&p, SysBase);
    kprintf("INPUTTASK CREATED\n");
    
    /* No need for these anymore */
    FreeSignal(p.ok_signal);
    FreeSignal(p.fail_signal);
    
    return lsd->input_task;
}
Exemple #15
0
int main()
{
    APTR ProcessorBase;
    IPTR args[6] = { 0, 0, 0, 0, 0, 0 };
    struct RDArgs *rda;
    int max_cpus = 0;
    int max_iter = 0;
    int req_width = 0, req_height = 0;
    char tmpbuf[200];
    int explicit_mode = 0;
    struct MsgPort *timerPort = CreateMsgPort();
    struct timerequest *tr = CreateIORequest(timerPort, sizeof(struct timerequest));
    struct TimerBase *TimerBase = NULL;
    struct timeval start_time;
    struct timeval now;

    struct Window *displayWin;
    struct BitMap *outputBMap = NULL;

    IPTR coreCount = 1;
    struct TagItem tags[] =
        {
            {GCIT_NumberOfProcessors, (IPTR)&coreCount},
            {0, (IPTR)NULL}};

    ProcessorBase = OpenResource(PROCESSORNAME);
    if (!ProcessorBase)
        return 0;

    KernelBase = OpenResource("kernel.resource");
    if (!KernelBase)
        return 0;

    if (timerPort)
    {
        FreeSignal(timerPort->mp_SigBit);
        timerPort->mp_SigBit = -1;
        timerPort->mp_Flags = PA_IGNORE;
    }

    if (tr)
    {
        if (!OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)tr, 0))
        {
            TimerBase = (struct TimerBase *)tr->tr_node.io_Device;
        }
    } else return 0;

    GetCPUInfo(tags);

    D(bug("[SMP-Smallpt] %s: detected %d CPU cores\n", __func__, coreCount);)
Exemple #16
0
void AtaTaskInit (void)
{
	KPRINTF ("AtaTaskInit()");

	ata_pid = GetPID();
	
	if ((ata_buffer = KMalloc (ATA_BUFFER_SZ)) != NULL)
	{
		if ((ata_timer_signal = AllocSignal()) != -1)
		{
			if ((ata_alarm_signal = AllocSignal()) != -1)
			{
				if ((ata_msgport = CreateMsgPort()) != NULL)
				{
					if (AtaInitUnits() == 0)
					{
						ata_init_error = 0;
						KSignal (GetPPID(), SIG_INIT);
						return;
					}
					
					DeleteMsgPort (ata_msgport);
				}
				
				FreeSignal (ata_alarm_signal);
			}

			FreeSignal (ata_timer_signal);
		}
				
		KFree (ata_buffer);
	}
	
	ata_init_error = -1;	
	KSignal (GetPPID(), SIG_INIT);
	
	Exit(-1);
}
Exemple #17
0
void timer_exit(void *t)
{
    struct timer_s *timer = t;

    if (timer != NULL) {
        if ((BYTE)timer->TimerMP.mp_SigBit != -1) {
            if (timer->TimerBase != NULL) {
                CloseDevice((struct IORequest *)&timer->TimerIO);
            }
            FreeSignal(timer->TimerMP.mp_SigBit);
        }
        lib_FreeMem(timer, sizeof(*timer));
    }
}
Exemple #18
0
/*************
 * FUNCTION:		CreateRexxHost
 * VERSION:			0.1 08.03.1995
 * DESCRIPTION:	Creates a RexxHost (special MsgPort) with a given name.
 *						Returns NULL if port already exists.
 * INPUT:			HostName
 * OUTPUT:			RexxHost
 * HISTORY:       DATE		NAME		COMMENT
 *						08.03.95	ah			first release
 *************/
struct MsgPort *CreateRexxHost(STRPTR HostName)
{
	struct MsgPort *RexxHost;

	/* Valid name given? */
	if(HostName && HostName[0])
	{
		/* Already present? */
		if(!FindPort((char *)HostName))
		{
			/* Allocate the port body. */
			RexxHost = (struct MsgPort *)AllocMem(sizeof(struct MsgPort),MEMF_PUBLIC | MEMF_CLEAR);
			if(RexxHost)
			{
				/* Allocate a signal bit. */
				if((RexxHost->mp_SigBit = AllocSignal(-1)) != -1)
				{
					/* Initialize the MsgPort node head. */
					RexxHost->mp_Node.ln_Type	= NT_MSGPORT;
					RexxHost->mp_Node.ln_Pri	= 0;

					/* Allocate memory for MsgPort name. */
					RexxHost->mp_Node.ln_Name = (char *)AllocMem(strlen((char *)HostName)+1,MEMF_PUBLIC);
					if(RexxHost->mp_Node.ln_Name)
					{
						/* Copy the name. */
						strcpy(RexxHost->mp_Node.ln_Name,(char *)HostName);

						/* Deal with the rest of the flags. */
						RexxHost->mp_Flags	= PA_SIGNAL;
						RexxHost->mp_SigTask	= FindTask(NULL);

						/* Finally add it to the public port list. */
						AddPort(RexxHost);

						/* And return it to the caller. */
						return(RexxHost);
					}
					FreeSignal(RexxHost->mp_SigBit);
				}
				FreeMem(RexxHost,sizeof(struct MsgPort));
			}
		}
	}
	return(NULL);
}
Exemple #19
0
void par_shutdown(void)
{
    if(alloc_flags & 8) {
        FreeSignal(intSig);
    }
    if (alloc_flags & 4) {
        DISABLEINT;
        CLEARINT;
        RemICRVector(cia_base, CIAICRB_FLG, &irq);
    }
    if (alloc_flags & 2) {
        FreeMiscResource(MR_PARALLELBITS);
    }
    if (alloc_flags & 1) {
        FreeMiscResource(MR_PARALLELPORT);
    }
    alloc_flags = 0;
}
Exemple #20
0
/*************
 * FUNCTION:		DeleteRexxHost
 * VERSION:			0.1 08.03.1995
 * DESCRIPTION:	Deletes a MsgPort as created by CreateRexxHost().
 *						Returns NULL, so user can do 'Host = DeleteRexxHost(Host);'
 * INPUT:			RexxHost
 * OUTPUT:			NULL
 * HISTORY:       DATE		NAME		COMMENT
 *						08.03.95	ah			first release
 *************/
void *DeleteRexxHost(struct MsgPort *RexxHost)
{
	/* Valid host port given? */
	if(RexxHost)
	{
		/* Remove it from the public list. */
		RemPort(RexxHost);

		/* Free the name. */
		FreeMem(RexxHost->mp_Node.ln_Name,strlen(RexxHost->mp_Node.ln_Name)+1);

		/* Free the allocated signal bit. */
		FreeSignal(RexxHost->mp_SigBit);

		/* Free the body. */
		FreeMem(RexxHost,sizeof(struct MsgPort));
	}
	return(NULL);
}
Exemple #21
0
struct MsgPort *CreatePort(CONST_STRPTR name,LONG pri)
{   APTR SysBase = *(APTR *)4L;
    struct MsgPort *port = NULL;
    UBYTE portsig;

    if ((BYTE)(portsig=AllocSignal(-1)) >= 0) {
        if (!(port=AllocMem(sizeof(*port),MEMF_CLEAR|MEMF_PUBLIC)))
            FreeSignal(portsig);
        else {
            port->mp_Node.ln_Type = NT_MSGPORT;
            port->mp_Node.ln_Pri  = pri;
            port->mp_Node.ln_Name = name;
            /* done via AllocMem
            port->mp_Flags        = PA_SIGNAL;
            */
            port->mp_SigBit       = portsig;
            port->mp_SigTask      = FindTask(NULL);
            NEWLIST(&port->mp_MsgList);
            if (port->mp_Node.ln_Name)
                AddPort(port);
        }
    }
    return port;
}
Exemple #22
0
/*************
 * FUNCTION:		SendRexxMsg
 * VERSION:			0.1 08.03.1995
 * DESCRIPTION:	Sends a single (or a list of) command(s) to Rexx host
 *						and returns the secondary result
 * INPUT:			HostName			name of host
 *						MsgList			messagelist (SingleMsg must be NULL)
 *						SingleMsg		single message (MsgList must be NULL)
 *						GetResult		TRUE: get results
 * OUTPUT:			secondary result
 * HISTORY:       DATE		NAME		COMMENT
 *						08.03.95	ah			first release
 *************/
ULONG SendRexxMsg(STRPTR HostName,STRPTR *MsgList,STRPTR SingleMsg,LONG GetResult)
{
	struct RexxMsg *RexxMessage;
	struct MsgPort *HostPort,*ReplyPort;
	ULONG Result = 0;
	SHORT i;

	/* Valid pointers given? */
	if(HostName && (MsgList || SingleMsg))
	{
		/* Can we find the host? */
		HostPort = (struct MsgPort *)FindPort((char *)HostName);
		if(HostPort)
		{
			/* Allocate a reply port. */
			ReplyPort = (struct MsgPort *)AllocMem(sizeof(struct MsgPort),MEMF_PUBLIC | MEMF_CLEAR);
			if(ReplyPort)
			{
				ReplyPort->mp_SigBit = AllocSignal(-1);
				if(ReplyPort->mp_SigBit != -1)
				{
					ReplyPort->mp_Node.ln_Type	= NT_MSGPORT;
					ReplyPort->mp_Flags			= PA_SIGNAL;
					ReplyPort->mp_SigTask		= FindTask(NULL);

					ReplyPort->mp_MsgList.lh_Head = (struct Node *)&ReplyPort->mp_MsgList.lh_Tail;
					ReplyPort->mp_MsgList.lh_Tail = 0;
					ReplyPort->mp_MsgList.lh_TailPred = (struct Node *)&ReplyPort->mp_MsgList.lh_Head;

					/* Create a Rexx message. */
					RexxMessage = (struct RexxMsg *)CreateRexxMsg(ReplyPort,"",(char *)HostName);
					if(RexxMessage)
					{
						/* A list of arguments or only a single arg? */
						if(MsgList)
						{
							for(i=0 ; i<16 ; i++)
								RexxMessage->rm_Args[i] = MsgList[i];
						}
						else
							RexxMessage->rm_Args[0] = SingleMsg;

						/* Do we want result codes? */
						if(GetResult)
							RexxMessage->rm_Action = RXFF_RESULT;

						/* Send packet and wait for the reply. */
						PutMsg(HostPort,(struct Message *)RexxMessage);
						WaitPort(ReplyPort);

						/* Remember result. */
						if(GetResult && !RexxMessage->rm_Result1)
							Result = RexxMessage->rm_Result2;

						/* Remove Rexx message. */
						DeleteRexxMsg(RexxMessage);
					}
					/* Free reply port signal bit. */
					FreeSignal(ReplyPort->mp_SigBit);
				}
				/* Free the replyport itself. */
				FreeMem(ReplyPort,sizeof(struct MsgPort));
			}
		}
	}
	/* Return the result. */
	return(Result);
}
Exemple #23
0
pid_t __vfork(jmp_buf env)
{
    struct Task *this = FindTask(NULL);
    struct vfork_data *udata = AllocMem(sizeof(struct vfork_data), MEMF_ANY | MEMF_CLEAR);
    if(udata == NULL)
    {
	errno = ENOMEM;
	longjmp(env, -1);	
    }
    D(bug("__vfork: allocated udata %p\n", udata));
    bcopy(env, &udata->vfork_jump, sizeof(jmp_buf));

    struct TagItem tags[] =
    {
	{ NP_Entry,         (IPTR) launcher  },
	{ NP_CloseInput,    (IPTR) FALSE     },
	{ NP_CloseOutput,   (IPTR) FALSE     },
	{ NP_CloseError,    (IPTR) FALSE     },
        { NP_Cli,           (IPTR) TRUE      },
        { NP_Name,          (IPTR) "vfork()" },
        { NP_UserData,      (IPTR) udata     },
        { NP_NotifyOnDeath, (IPTR) TRUE      },
        { TAG_DONE,         0                }
    };

    udata->parent = this;
    
    struct arosc_privdata *ppriv = __get_arosc_privdata();
    udata->ppriv = ppriv;
    
    /* Store parent's vfork_data to restore it later */
    udata->prev = __get_arosc_privdata()->acpd_vfork_data;
    D(bug("__vfork: Saved old parent's vfork_data: %p\n", udata->prev));
                                        
    D(bug("__vfork: backuping startup buffer\n"));
    /* Backup startup buffer */
    CopyMem(&__aros_startup_jmp_buf, &udata->startup_jmp_buf, sizeof(jmp_buf));

    D(bug("__vfork: Allocating parent signal\n"));
    /* Allocate signal for child->parent communication */
    udata->parent_signal = AllocSignal(-1);
    if(udata->parent_signal == -1)
    {
	/* Couldn't allocate the signal, return -1 */
	FreeMem(udata, sizeof(struct vfork_data));
	errno = ENOMEM;
	longjmp(udata->vfork_jump, -1);    
    }
    
    D(bug("__vfork: Creating child\n"));
    udata->child = (struct Task*) CreateNewProc(tags);

    if(udata->child == NULL)
    {
	/* Something went wrong, return -1 */
	FreeMem(udata, sizeof(struct vfork_data));
	errno = ENOMEM; /* Most likely */
	longjmp(env, -1);
    }
    D(bug("__vfork: Child created %p, waiting to finish setup\n", udata->child));
    udata->child_id = GetETaskID(udata->child);
    D(bug("__vfork: Got unique child id: %d\n", udata->child_id));

    /* Wait for child to finish setup */
    Wait(1 << udata->parent_signal);
    
    if(udata->child_errno)
    {
	/* An error occured during child setup */
	errno = udata->child_errno;
	longjmp(env, -1);
    }
    
    D(bug("__vfork: Setting jmp_buf at %p in %p\n", __aros_startup, &__aros_startup_jmp_buf));
    if(setjmp(__aros_startup_jmp_buf))
    {
	D(bug("__vfork: child exited\n or executed\n"));

	if(!GETUDATA->child_executed)
	{
	    D(bug("__vfork: not executed\n"));
	    ((struct aros_startup*) GetIntETask(GETUDATA->child)->iet_startup)->as_startup_error = __aros_startup_error;
	    D(bug("__vfork: Signaling child\n"));
	    Signal(GETUDATA->child, 1 << GETUDATA->child_signal);
	}

	D(bug("__vfork: Waiting for child to finish using udata\n"));
	/* Wait for child to finish using GETUDATA */
	Wait(1 << GETUDATA->parent_signal);

	D(bug("__vfork: fflushing\n"));
	fflush(NULL);

	D(bug("__vfork: restoring old fd_array\n"));
	/* Restore parent's old fd_array */
	((struct arosc_privdata *) GetIntETask(GETUDATA->parent)->iet_acpd)->acpd_fd_mempool = GETUDATA->parent_acpd_fd_mempool;
	((struct arosc_privdata *) GetIntETask(GETUDATA->parent)->iet_acpd)->acpd_numslots = GETUDATA->parent_acpd_numslots;
	((struct arosc_privdata *) GetIntETask(GETUDATA->parent)->iet_acpd)->acpd_fd_array =  GETUDATA->parent_acpd_fd_array;

	D(bug("__vfork: restoring startup buffer\n"));
	/* Restore parent startup buffer */
	CopyMem(&GETUDATA->startup_jmp_buf, &__aros_startup_jmp_buf, sizeof(jmp_buf));

	D(bug("__vfork: freeing parent signal\n"));
	FreeSignal(GETUDATA->parent_signal);

        errno = GETUDATA->child_errno;
        
	FreeAndJump(GETUDATA);
	assert(0); /* not reached */
        return (pid_t) 1;
    }

    /* Remember parent fd descriptor table */
    udata->parent_acpd_fd_mempool = ppriv->acpd_fd_mempool;
    udata->parent_acpd_numslots = ppriv->acpd_numslots;
    udata->parent_acpd_fd_array = ppriv->acpd_fd_array;
    
    /* Pretend to be running as the child created by vfork */
    ppriv->acpd_vfork_data = udata;
    ppriv->acpd_flags |= PRETEND_CHILD;
    ppriv->acpd_fd_mempool = udata->cpriv->acpd_fd_mempool;
    ppriv->acpd_numslots = udata->cpriv->acpd_numslots;
    ppriv->acpd_fd_array = udata->cpriv->acpd_fd_array;
    
    D(bug("__vfork: Jumping to jmp_buf %p\n", &udata->vfork_jump));
    D(bug("__vfork: ip: %p, stack: %p\n", udata->vfork_jump[0].retaddr, udata->vfork_jump[0].regs[_JMPLEN - 1]));
    vfork_longjmp(udata->vfork_jump, 0);
    assert(0); /* not reached */
    return (pid_t) 0;
}
Exemple #24
0
int AtaInitUnits (void)
{
	int t;
	uint32 size;
	struct MountEnviron *me;
	struct Partition *partition_table;
	int p, hd_cnt, cd_cnt;
	uint16 general_config;

	
	KPRINTF ("AtaInitUnits()");
	
	use_interrupts = FALSE;

	for (t=0; t<4; t++)
	{
		ata_drive[t].enabled = FALSE;
		ata_drive[t].config = ATA_CONFIG_NONE;
		ata_drive[t].reference_cnt = 0;
		
		
		switch (t)
		{
			case 0:
				ata_drive[t].ldhpref = LDH_DEFAULT | (0 << 4);
				break;
			
			case 1:
				ata_drive[t].ldhpref = LDH_DEFAULT | (1 << 4);
				break;
			
			case 2:
				ata_drive[t].ldhpref = LDH_DEFAULT | (0 << 4);
				break;
				
			case 3:
				ata_drive[t].ldhpref = LDH_DEFAULT | (1 << 4);
				break;
		}
		
		
		LIST_INIT (&ata_drive[t].callback_list);
		
		if (t <2)
			ata_drive[t].base = REG_BASE0;
		else
			ata_drive[t].base = REG_BASE1;
	}
	
	ata_drive[0].device[0] = &ata_drive[0];
	ata_drive[0].device[1] = &ata_drive[1];	
	
	ata_drive[1].device[0] = &ata_drive[0];
	ata_drive[1].device[1] = &ata_drive[1];	
	
	ata_drive[2].device[0] = &ata_drive[2];
	ata_drive[2].device[1] = &ata_drive[3];	
	
	ata_drive[3].device[0] = &ata_drive[2];
	ata_drive[3].device[1] = &ata_drive[3];	
	
	AtaDetect (&ata_drive[0], &ata_drive[1]);
	AtaDetect (&ata_drive[2], &ata_drive[3]);
	
	
	
	
	if (ata_drive[0].config != ATA_CONFIG_UNKNOWN ||
		ata_drive[1].config != ATA_CONFIG_UNKNOWN)
	{

		if ((ata_isr14_signal = AllocSignal()) != -1)
		{
			if ((ata_isr14_handler = ISRHandlerInsert (14, AtaISRHandler, NULL)) != NULL)
			{
				ata_isr14_enabled = TRUE;
				ata_drive[0].isr_signal = ata_isr14_signal;
				ata_drive[1].isr_signal = ata_isr14_signal;
			}
			else
				FreeSignal (ata_isr14_signal);
		}	
		
	}
	
	if (ata_drive[2].config != ATA_CONFIG_UNKNOWN ||
		ata_drive[3].config != ATA_CONFIG_UNKNOWN)
	{
		if ((ata_isr15_signal = AllocSignal()) != -1)
		{
			if ((ata_isr15_handler = ISRHandlerInsert (15, AtaISRHandler, NULL)) != NULL)
			{
				ata_isr15_enabled = TRUE;
				ata_drive[2].isr_signal = ata_isr15_signal;
				ata_drive[3].isr_signal = ata_isr15_signal;
			}
			else
				FreeSignal (ata_isr15_signal);
		}	

	}

	use_interrupts = TRUE;

	for (t=0; t<4; t++)
	{
		if (ata_drive[t].config == ATA_CONFIG_ATA)
		{
			KPRINTF ("ATA Drive (%d) is ATA", t);
		
			if (AtaIdentify (&ata_drive[t], ata_buffer) == 0)
			{
				ata_drive[t].pcylinders = id_word(1);
				ata_drive[t].pheads = id_word(3);
				ata_drive[t].psectors = id_word(6);
			
				size = (uint32) ata_drive[t].pcylinders
								* ata_drive[t].pheads
								* ata_drive[t].psectors;
		
				if ((id_byte(49)[1] & 0x02) && size > 512L*1024*2)
				{
					ata_drive[t].ldhpref |= LDH_LBA;
					size = id_longword(60);
				}
			
				ata_drive[t].sector_sz = 512;
				ata_drive[t].size = size;
				ata_drive[t].disk_state = ATA_MEDIA_PRESENT;
				ata_drive[t].diskchange_cnt = 0;
				

				ata_drive[t].enabled = TRUE;
			}
		}
		else if (ata_drive[t].config == ATA_CONFIG_ATAPI)
		{
			KPRINTF ("ata_isr15_cnt = %d", ata_isr15_cnt);

		
			KPRINTF ("ATA Drive (%d) is ATAPI, RESETTING", t);

			AtapiReset (&ata_drive[t]);
			
			KPRINTF ("ATAPI RESET complete");
			KPRINTF ("ata_isr15_cnt = %d", ata_isr15_cnt);

			
			if (AtapiIdentify (&ata_drive[t], ata_buffer) == 0)
			{
				KPRINTF ("Atapi Identify OK on ATAPI device");
				KPRINTF ("ata_isr15_cnt = %d", ata_isr15_cnt);
			
				general_config = id_word (0);
						
				ata_drive[t].atapi_protocol_type = (general_config & 0xC000) >> 14;
				ata_drive[t].atapi_type  = (general_config & 0x1F00) >> 8;
				ata_drive[t].atapi_removable = (general_config & 0x0080) >> 7;
				ata_drive[t].atapi_cmd_drq_type = (general_config & 0x0060) >> 5;
				
				ata_drive[t].atapi_cmd_packet_size = ((general_config & 0x0001) == 1) ? 16 : 12;
				
				
				KPRINTF ("protocol_type = %d", ata_drive[t].atapi_protocol_type);
				KPRINTF ("atapi_type = %d", ata_drive[t].atapi_type);
				KPRINTF ("packet_size = %d", ata_drive[t].atapi_cmd_packet_size);
				
				
				if (ata_drive[t].atapi_protocol_type == ATAPI_PROTOCOL_ATAPI
							&& ata_drive[t].atapi_type == ATAPI_TYPE_CDROM
							&& ata_drive[t].atapi_cmd_packet_size == 12)
				{
					KPRINTF ("ATAPI CDROM DETECTED");
					
					ata_drive[t].sector_sz = 2048;
					ata_drive[t].size = 0;
					ata_drive[t].enabled = TRUE;
					ata_drive[t].disk_state = AtapiMediaPresent (&ata_drive[t]);
					ata_drive[t].diskchange_cnt = 0;
				}
			}
		}
Exemple #25
0
LONG launcher()
{
    D(bug("launcher: Entered child launcher\n"));

    struct Task *this = FindTask(NULL);
    struct vfork_data *udata = this->tc_UserData;
    BYTE child_signal;
    struct Library *aroscbase = NULL;

    GetIntETask(this)->iet_startup = GetETask(this)->et_Result2 = AllocVec(sizeof(struct aros_startup), MEMF_ANY | MEMF_CLEAR);

    /* Allocate signal for parent->child communication */
    child_signal = udata->child_signal = AllocSignal(-1);
    D(bug("launcher: Allocated child signal: %d\n", udata->child_signal));
    if(udata->child_signal == -1)
    {
	/* Lie */
	udata->child_errno = ENOMEM;
	Signal(udata->parent, 1 << udata->parent_signal);
	return -1;
    }

    if(__register_init_fdarray(udata->ppriv->acpd_fd_array, udata->ppriv->acpd_numslots))
        aroscbase = OpenLibrary((STRPTR) "arosc.library", 0);
    if(!aroscbase)
    {
	FreeSignal(child_signal);
	udata->child_errno = ENOMEM;
	Signal(udata->parent, 1 << udata->parent_signal);
	return -1;	
    }
    
    udata->cpriv = __get_arosc_privdata();
    udata->cpriv->acpd_parent_does_upath = udata->ppriv->acpd_doupath;
    udata->cpriv->acpd_flags |= DO_NOT_CLONE_ENV_VARS;

    if(setjmp(__aros_startup_jmp_buf) == 0)
    {
        /* Setup complete, signal parent */
        D(bug("launcher: Signaling parent that we finished setup\n"));
        Signal(udata->parent, 1 << udata->parent_signal);

        D(bug("launcher: Child waiting for exec or exit\n"));
        Wait(1 << udata->child_signal);

        if(udata->child_executed)
        {
            APTR exec_id;
            BPTR dir;
            
            D(bug("launcher: child executed\n"));
            
            /* Set current dir to parent's current dir */
            dir = DupLock(((struct Process *)udata->parent)->pr_CurrentDir);
            UnLock(CurrentDir(dir));
            /* Don't mind updating aroscbase->acb_startup_cd_changed as we will
               exit from process after __exec_do has finished */

            /* Filenames passed from parent obey parent's __doupath */
            __doupath = udata->cpriv->acpd_parent_does_upath;
            D(bug("launcher: __doupath == %d for __exec_prepare()\n", __doupath));
            
            exec_id = udata->exec_id = __exec_prepare(
                udata->exec_filename,
                udata->exec_searchpath,
                udata->exec_argv,
                udata->exec_envp
            );
            
            udata->child_errno = errno;

            /* Clear __doupath again, command will set it if wanted */
            __doupath = 0;
            
            D(bug("launcher: informing parent that we have run __exec_prepare\n"));
            /* Inform parent that we have run __exec_prepare */
            Signal(udata->parent, 1 << udata->parent_signal);
            
            /* Wait 'till __exec_do() is called on parent process */
            D(bug("launcher: Waiting parent to get the result\n"));
            Wait(1 << udata->child_signal);

            D(bug("launcher: informing parent that we won't use udata anymore\n"));
            /* Inform parent that we won't use udata anymore */
            Signal(udata->parent, 1 << udata->parent_signal);

            if (exec_id)
            {
                D(bug("launcher: executing command\n"));
                __exec_do(exec_id);
                
                assert(0); /* Should not be reached */
            }
            else
            {
                D(bug("launcher: exit because execve returned with an error\n"));
                _exit(0);
            }
        }
        else
        {
            D(bug("launcher: informing parent that we won't use udata anymore\n"));
            /* Inform parent that we won't use udata anymore */
            Signal(udata->parent, 1 << udata->parent_signal);
        }
    }
    else
    {
        D(bug("launcher: freeing child_signal\n"));
        FreeSignal(child_signal);
        CloseLibrary(aroscbase);
    }
    
    return 0;
}
Exemple #26
0
void CloseClock(void){
#ifdef _AMIGA
	FreeSignal(clocksig);
#endif
//	FreeRSemaphore(ClockSemaphore);
}
static void
Slave( struct ExecBase* SysBase )
{
  struct AHIAudioCtrlDrv* AudioCtrl;
  struct DriverBase*      AHIsubBase;
  struct AROSBase*        AROSBase;
  BOOL                    running;
  ULONG                   signals;

  int bytes_in_buffer  = 0;
  int offset_in_buffer = 0;

  AudioCtrl  = (struct AHIAudioCtrlDrv*) FindTask( NULL )->tc_UserData;
  AHIsubBase = (struct DriverBase*) dd->ahisubbase;
  AROSBase   = (struct AROSBase*) AHIsubBase;

  dd->slavesignal = AllocSignal( -1 );

  if( dd->slavesignal != -1 )
  {
    // Everything set up. Tell Master we're alive and healthy.

    Signal( (struct Task*) dd->mastertask,
            1L << dd->mastersignal );

    running = TRUE;

    // The main playback loop follow

    while( running )
    {      
      signals = SetSignal(0L,0L);

//    KPrintF("++++ arosdriver_after signal checking\n");
      if( signals & ( SIGBREAKF_CTRL_C | (1L << dd->slavesignal) ) )
      {
        running = FALSE;
      }
      else
      {
	int skip_mix;
	int bytes_avail;
	
	// First Delay() until there is at least one fragment free

	while( TRUE )
	{
	  int frag_avail, frag_alloc, frag_size;
	
	  OSS_GetOutputInfo( &frag_avail, &frag_alloc, &frag_size,
			     &bytes_avail );
	  
//	  KPrintF( "%ld fragments available, %ld alloced (%ld bytes each). %ld bytes total\n", frag_avail, frag_alloc, frag_size, bytes_avail );
	  
	  if( frag_avail == 0 )
	  {
	    // This is actually quite a bit too long delay :-( For
	    // comparison, the SB Live/Audigy driver uses 1/1000 s
	    // polling ...
//	    KPrintF("Delay\n");
    	  #if USE_TIMERTICK
	    SmallDelay(SysBase);
	  #else
	    Delay( 1 );
	  #endif
	  }
	  else
	  {
	    break;
	  }
	}

	skip_mix = 0;/*CallHookA( AudioCtrl->ahiac_PreTimerFunc,
		       (Object*) AudioCtrl, 0 );*/

	while( bytes_avail > 0 )
	{
//	  KPrintF( "%ld bytes in current buffer.\n", bytes_in_buffer );
	  
	  if( bytes_in_buffer == 0 )
	  {
	    int skip     = 0;
	    int offset   = 0;

	    int samples  = 0;
	    int bytes    = 0;
	  
	    int i;
	  
	    WORD* src;
	    WORD* dst;

	    CallHookPkt( AudioCtrl->ahiac_PlayerFunc, AudioCtrl, NULL );

	    samples = AudioCtrl->ahiac_BuffSamples;
	    bytes   = samples * 2; // one 16 bit sample is 2 bytes

	    switch( AudioCtrl->ahiac_BuffType )
	    {
	      case AHIST_M16S:
		skip = 1;
		offset = 0;
		break;
	    
	      case AHIST_M32S:
		skip = 2;
		offset = 1;
		break;

	      case AHIST_S16S:
		skip = 1;
		offset = 0;
		samples *= 2;
		bytes *= 2;
		break;

	      case AHIST_S32S:
		skip = 2;
		offset = 1;
		samples *= 2;
		bytes *= 2;
		break;
	    }

	    bytes_in_buffer  = bytes;
	    offset_in_buffer = 0;

	    if( ! skip_mix )
	    {
	      CallHookPkt( AudioCtrl->ahiac_MixerFunc, AudioCtrl,
			   dd->mixbuffer );
	    }

	    src = ((WORD*) dd->mixbuffer) + offset;
	    dst = dd->mixbuffer;

	    for( i = 0; i < samples; ++i )
	    {
	      *dst++ = *src;
	      src += skip;
	    }

//	    KPrintF( "Mixed %ld/%ld new bytes/samples\n", bytes, samples );
	  }

	  while( bytes_in_buffer > 0 &&
		 bytes_avail > 0 )
	  {
	    int written;
    	    int counter = 0;
    	    do
	    {
	    	written = OSS_Write( dd->mixbuffer + offset_in_buffer,
				    min( bytes_in_buffer, bytes_avail ) );
	    	if (counter > 10)
		{
		    if (written < 0) written = 0;
		    break;
		}
		
		if (written < 0) KPrintF("OSS_Write returned %ld. counter %ld  bytes_in_buffer %ld  bytes_avail %ld\n",
		    	    	written, counter, bytes_in_buffer, bytes_avail);
		
		counter++;
		
    	    } while (written < 0);
	    
	    bytes_in_buffer  -= written;
	    offset_in_buffer += written;
	    bytes_avail      -= written;
	    
//	    KPrintF( "Wrote %ld bytes (%ld bytes in buffer, offset=%ld, %ld bytes available in OSS buffers\n",
//		     written, bytes_in_buffer, offset_in_buffer, bytes_avail );
	  }
	}

	CallHookA( AudioCtrl->ahiac_PostTimerFunc, (Object*) AudioCtrl, 0 );
      }
    }
  }

  FreeSignal( dd->slavesignal );
  dd->slavesignal = -1;

  Forbid();

  // Tell the Master we're dying

  Signal( (struct Task*) dd->mastertask,
          1L << dd->mastersignal );

  dd->slavetask = NULL;

  // Multitaking will resume when we are dead.
}
Exemple #28
0
// Quit the program
void quit(BOOL script)
{
	// If main status window is open, close it
	if (main_status)
	{
		CloseProgressWindow(main_status);
		main_status=0;
	}

	if (GUI)
	{
		// Clear 'startup' flag for scripts
		GUI->flags&=~GUIF_DONE_STARTUP;

		// Close commodities
		cx_remove(GUI->cx);

		// Update environment settings
		env_update_settings(1);

		// Stop notify request
		RemoveNotifyRequest(GUI->notify_req);
		GUI->notify_req=0;

		// Is there a hide appicon?
		if (GUI->hide_appicon)
		{
			RemoveAppIcon(GUI->hide_appicon);
			FreeCachedDiskObject(GUI->hide_diskobject);
		}

		// Or an appmenuitem?
		if (GUI->hide_appitem) RemoveAppMenuItem(GUI->hide_appitem);

		// Launch shutdown script
		if (script)
			RunScript(SCRIPT_SHUTDOWN,0);

		// Set quit flag
		GUI->flags|=GUIF_PENDING_QUIT;

		// Shut the display down
		close_display(CLOSE_ALL,TRUE);

		// Send quit notifications
		quit_notify();

		// Stop notifications
		stop_file_notify(GUI->pattern_notify);
		stop_file_notify(GUI->font_notify);
		stop_file_notify(GUI->modules_notify);
		stop_file_notify(GUI->commands_notify);
		stop_file_notify(GUI->env_notify);
		stop_file_notify(GUI->desktop_notify);
		stop_file_notify(GUI->filetype_notify);

		// Free application port
		if (GUI->appmsg_port)
		{
			DOpusAppMessage *amsg;
			RemPort(GUI->appmsg_port);
			while ((amsg=(DOpusAppMessage *)GetMsg(GUI->appmsg_port)))
				ReplyAppMessage(amsg);
			DeleteMsgPort(GUI->appmsg_port);
			GUI->appmsg_port=0;

			// Remove public semaphore
			RemSemaphore((struct SignalSemaphore *)&pub_semaphore);
		}

		// Flush IPC port
		IPC_Flush(&main_ipc);

		// Close all processes
		IPC_ListQuit(&GUI->lister_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->group_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->buttons_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->startmenu_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->process_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->function_list,&main_ipc,0,TRUE);

		// Free buffers
		buffers_clear(0);

		// Remove all handlers
		RemFunctionTrap("*","#?");

		// Free filetypes
		FreeMemHandle(GUI->filetype_memory);

		// Flush the filetype cache
		ClearFiletypeCache();

		// Free lister toolbar
		FreeToolBar(GUI->toolbar);

		// Free menus and hotkeys
		CloseButtonBank(GUI->lister_menu);
		CloseButtonBank(GUI->hotkeys);

		// Free user menus
		CloseButtonBank(GUI->user_menu);
		FreeVec(GUI->user_menu_data);

		// Free backdrop list
		backdrop_free(GUI->backdrop);

		// Free icons
		if (GUI->lister_icon) FreeCachedDiskObject(GUI->lister_icon);
		if (GUI->button_icon) FreeCachedDiskObject(GUI->button_icon);

		// Free arrow image
		CloseImage(GUI->toolbar_arrow_image);

#ifdef __amigaos3__
		FreeVec(arrow_hi_data_chip);
		FreeVec(arrow_lo_data_chip);
		FreeVec(small_arrow_chip);
		FreeVec(big_arrow_chip);
#ifndef USE_SCREENTITLE
		FreeVec(moon_big_data_chip);
		FreeVec(moon_small_data_chip);
#endif
		FreeVec(command_arrow_chip);
		FreeVec(parent_arrow_chip);
#endif

		// Free screen signal
		if (GUI->screen_signal!=-1) FreeSignal(GUI->screen_signal);

		// Delete notify port
		if (GUI->notify_port) DeleteMsgPort(GUI->notify_port);

		// Free position memory
		FreeMemHandle(GUI->position_memory);

		// Free command history
		Att_RemList(GUI->command_history,0);

		// Delete icon positioning port
		DeleteMsgPort(GUI->iconpos_port);

		// Free popup menu
		PopUpFreeHandle(GUI->desktop_menu);

		// Clear requester pattern hook in library
		if (GUI->flags2&GUIF2_BACKFILL_SET)
			SetReqBackFill(0,0);
	}

	// Free scripts
	FreeScripts();

	// Free environment
	environment_free(environment);
	
	// Delete main message ports
	IPC_Flush(&main_ipc);
	DeleteMsgPort(main_ipc.command_port);
	DeleteMsgPort(main_ipc.reply_port);

	// Pause here for a couple of seconds to let everything clean up
	Delay(3*50);

	// Free global data
	FreeMemHandle(global_memory_pool);

	// Delete any temporary files
	delete_temp_files(0);

	// Free locale data
	free_locale_data(&locale);

	// Close input device
	if (InputBase) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IInput);
	#endif
	CloseDevice((struct IORequest *)&input_req);
	}

	// Close timer device
	if (TimerBase) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ITimer);
	#endif
	CloseDevice((struct IORequest *)&timer_req);
	}

	// Close console device
	if (ConsoleDevice) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IConsole);
	#endif
	CloseDevice((struct IORequest *)&console_req);
	}

	// Close libraries
	#ifdef __amigaos4__
	DropInterface((struct Interface *)Imu);
	#endif
	CloseLibrary(muBase);
	
#ifndef __amigaos3__	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)INewIcon);
	#endif
	CloseLibrary((struct Library *)NewIconBase);
#endif

	#ifdef __amigaos4__
	DropInterface((struct Interface *)ICyberGfx);
	#endif
	CloseLibrary(CyberGfxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IAmigaGuide);
	#endif
	CloseLibrary(AmigaGuideBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDataTypes);
	#endif
	CloseLibrary(DataTypesBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IAsl);
	#endif
	CloseLibrary(AslBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IIcon);
	#endif
	CloseLibrary(IconBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDiskfont);
	#endif
	CloseLibrary(DiskfontBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IWorkbench);
	#endif
	CloseLibrary(WorkbenchBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ICommodities);
	#endif
	CloseLibrary(CxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IRexxSys);
	#endif
	CloseLibrary((struct Library *)RexxSysBase); 
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IUtility);
	#endif
	CloseLibrary(UtilityBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IGadTools);
	#endif
	CloseLibrary(GadToolsBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ILayers);
	#endif
	CloseLibrary((struct Library *)LayersBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IGraphics);
	#endif
	CloseLibrary((struct Library *)GfxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IIntuition);
	#endif
	CloseLibrary((struct Library *)IntuitionBase);
	
	// Restore old current directory?
	if (old_current_dir)
	{
		UnLock(CurrentDir(old_current_dir));
	}

	// Close the dopus5.library
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDOpus);
	#endif
	CloseLibrary(DOpusBase);

	// Outahere!
	exit(0);
}
Exemple #29
0
VOID DispatcherThread(struct MOSWriteHandle* h)
{
	struct MsgPort*	  ahi_port = NULL;
	struct AHIRequest*  ahi_request = NULL;
	struct AHIAudioCtrl*ahi_control = NULL;
	BYTE*					  sample_bufs = NULL;
	ULONG					  sample_size = 2;
	BYTE					  ahi_device = -1;
	LONG					  switch_sig_bit = -1;
	LONG				     locked_buf = -1;
	struct DispatcherStartupMsg *startup_msg;
	struct DispatcherInitReport *init_report;
	struct MsgPort     *task_port = NULL;
	struct ExecBase *SysBase = *(struct ExecBase **) 4;

	init_report = (struct DispatcherInitReport *) AllocVec(sizeof (struct DispatcherInitReport), MEMF_PUBLIC | MEMF_CLEAR);
	if (init_report == NULL)
		return;

	NewGetTaskAttrsA(NULL, &task_port, sizeof (task_port), TASKINFOTYPE_TASKMSGPORT, NULL);
	NewGetTaskAttrsA(NULL, &startup_msg, sizeof (startup_msg), TASKINFOTYPE_STARTUPMSG, NULL);

	if (task_port == NULL || startup_msg == NULL)
	{
		FreeVec(init_report);
		return;
	}

	startup_msg->dsm_Result = -1;
	switch_sig_bit = AllocSignal(-1);

	if (switch_sig_bit != -1 && (ahi_port = CreateMsgPort()))
	{
		if ((ahi_request = (struct AHIRequest *) CreateIORequest(ahi_port, sizeof (struct AHIRequest))))
		{
			ahi_request->ahir_Version = 4;
			if ((ahi_device = OpenDevice(AHINAME, AHI_NO_UNIT, (struct IORequest *) ahi_request, 0)) == 0)
			{
				AHIBase = (struct Library*) ahi_request->ahir_Std.io_Device;

				/*dprintf("AllocAudio with %d channels, %d sounds and frequency %d\n", h->wh_Channels, AHI_BUFFERS, h->wh_Frequency);*/
				ahi_control = AHI_AllocAudio(AHIA_AudioID,   AHI_DEFAULT_ID,
													  AHIA_Channels,  h->wh_Channels,
													  AHIA_Sounds,	   AHI_BUFFERS,
													  AHIA_MixFreq,   h->wh_Frequency,
													  AHIA_SoundFunc, (ULONG) &OpenAL_SoundHook,
													  AHIA_UserData,	(ULONG) h,
													  TAG_DONE
													 );
				if (ahi_control)
				{
					ULONG buf_size;
					ULONG samples, fs, fm;

					AHI_GetAudioAttrs(AHI_INVALID_ID, ahi_control, AHIDB_MaxPlaySamples, (ULONG) &samples, TAG_DONE);
					AHI_ControlAudio(ahi_control, AHIC_MixFreq_Query, (ULONG) &fm, TAG_DONE);
					fs = h->wh_Frequency;

					buf_size = samples*fs/fm;
					/*dprintf("OpenAL: Minimum buffer size is %d, requested buffer size is %d\n", buf_size, h->wh_BufSize);*/
					if (buf_size > h->wh_BufSize)
						h->wh_BufSize = buf_size;

					sample_bufs = AllocVec(h->wh_BufSize*AHI_BUFFERS, MEMF_PUBLIC | MEMF_CLEAR);
					if (sample_bufs)
					{
						struct Buffer* bn;
						ULONG	buf;
						LONG err = AHIE_OK;

						sample_size = AHI_SampleFrameSize(h->wh_SampleType);

						for (buf = 0; buf < AHI_BUFFERS && err == AHIE_OK; buf++)
						{
							bn = &h->wh_Buffers[buf];
							bn->bn_SampleNo = buf;
							bn->bn_SampleInfo.ahisi_Type = h->wh_SampleType;
							bn->bn_SampleInfo.ahisi_Address = &sample_bufs[buf*h->wh_BufSize];
							bn->bn_SampleInfo.ahisi_Length = h->wh_BufSize/sample_size;
							InitSemaphore(&bn->bn_Semaphore);
							bn->bn_FillSize = 0;
							err = AHI_LoadSound(buf, AHIST_DYNAMICSAMPLE, &bn->bn_SampleInfo, ahi_control);
						}

						if (err != AHIE_OK)
						{
							FreeVec(sample_bufs);
							sample_bufs = NULL;
						}
					}
				}
			}
		}
	}

	if (sample_bufs)
	{
		BOOL dispatcher_running = TRUE;
		ULONG signal_mask = 1 << task_port->mp_SigBit;
		ULONG signal_set;
		struct MsgPort *reply_port;

		reply_port = CreateMsgPort();
		if (reply_port == NULL)
			reply_port = task_port;

		if (startup_msg)
			startup_msg->dsm_Result = 0;
		init_report->dir_Msg.mn_Node.ln_Type = NT_MESSAGE;
		init_report->dir_Msg.mn_ReplyPort = reply_port;
		init_report->dir_Msg.mn_Length = sizeof (struct DispatcherInitReport);
		AHI_ControlAudio(ahi_control, AHIC_MixFreq_Query, (ULONG) &init_report->dir_RealFrequency, TAG_DONE);
		init_report->dir_RealBufSize = h->wh_BufSize;
		PutMsg(startup_msg->dsm_Msg.mn_ReplyPort, (struct Message*) init_report);
		WaitPort(reply_port);
		GetMsg(reply_port);
		FreeVec(init_report);
		init_report = NULL;

		if (reply_port != task_port)
			DeleteMsgPort(reply_port);

		h->wh_SwitchSignal = 1UL << switch_sig_bit;
		h->wh_ReadBuf = 0;
		while (dispatcher_running)
		{
			signal_set = Wait(signal_mask);

			if (signal_set & (1 << task_port->mp_SigBit))
			{
				struct DispatcherMsg *msg;

				while ((msg = (struct DispatcherMsg *) GetMsg(task_port)))
				{
					if (msg->dm_Msg.mn_Length == sizeof (struct DispatcherMsg))
					{
						switch (msg->dm_Command)
						{
							case DISPATCHER_CMD_START:
							{
								/*
								 * First buffer has been filled and we were previously not
								 * playing any sound yet
								 */
								ULONG chan;
								ULONG cur_buf;

								cur_buf = h->wh_ReadBuf;
								AHI_ControlAudio(ahi_control, AHIC_Play, TRUE, TAG_DONE);

								/* Lock first audio buffer */
								ObtainSemaphore(&h->wh_Buffers[cur_buf].bn_Semaphore);
								locked_buf = cur_buf;

								for (chan = 0; chan < h->wh_Channels; chan++)
								{
									AHI_SetFreq(chan, h->wh_Frequency, ahi_control, AHISF_IMM);
									AHI_SetVol(chan, 0x10000L, -0x8000L, ahi_control, AHISF_IMM);
									AHI_SetSound(chan, cur_buf, 0, 0, ahi_control, AHISF_IMM);
								}

								Wait(1 << switch_sig_bit);
								cur_buf++;
								if (cur_buf >= AHI_BUFFERS)
									cur_buf = 0;
								h->wh_ReadBuf = cur_buf;

								signal_mask |= 1UL << switch_sig_bit;
								break;
							}

							case DISPATCHER_CMD_PAUSE:
							case DISPATCHER_CMD_RESUME:
								AHI_ControlAudio(ahi_control, AHIC_Play, msg->dm_Command == DISPATCHER_CMD_RESUME, TAG_DONE);
								break;

							case DISPATCHER_CMD_BREAK:
								/* Break requests and quit */
								/*dprintf("Dispatcher thread: break requested\n");*/
								AHI_ControlAudio(ahi_control, AHIC_Play, FALSE, TAG_DONE);
								dispatcher_running = FALSE;
								break;
						}
					}

					ReplyMsg((struct Message *) msg);
				}
			}

			if (signal_set & (1UL << switch_sig_bit))
			{
				/* Switch to next read buffer */
				ULONG cur_buf;

				cur_buf = h->wh_ReadBuf;
				/*dprintf("Dispatcher thread: buffer switch requested. Releasing lock on %d, locking %d\n", locked_buf, cur_buf);*/
				memset(h->wh_Buffers[locked_buf].bn_SampleInfo.ahisi_Address, 0, h->wh_BufSize);
				ReleaseSemaphore(&h->wh_Buffers[locked_buf].bn_Semaphore);
				cur_buf++;
				if (cur_buf >= AHI_BUFFERS)
					cur_buf = 0;
				ObtainSemaphore(&h->wh_Buffers[cur_buf].bn_Semaphore);
				locked_buf = cur_buf;
				h->wh_ReadBuf = cur_buf;
				/*dprintf("Dispatcher thread: buffer switch done\n");*/
			}
		}
	}

	/* Cleanup */
	if (init_report)
	{
		FreeVec(init_report);
		init_report = NULL;
	}

	if (locked_buf != -1)
	{
		ReleaseSemaphore(&h->wh_Buffers[locked_buf].bn_Semaphore);
		locked_buf = -1;
	}

	if (switch_sig_bit != -1)
	{
		FreeSignal(switch_sig_bit);
		switch_sig_bit = -1;
	}

	if (ahi_control)
	{
		AHI_FreeAudio(ahi_control);  /* Also unloads all sounds */
		ahi_control = NULL;
	}

	if (ahi_request)
	{
		CloseDevice((struct IORequest*) ahi_request);
		DeleteIORequest((struct IORequest*) ahi_request);
		ahi_request = NULL;
		ahi_device = -1;
	}

	if (sample_bufs)
	{
		FreeVec(sample_bufs);
		sample_bufs = NULL;
	}

	if (ahi_port)
	{
		DeleteMsgPort(ahi_port);
		ahi_port = NULL;
	}
}
Exemple #30
0
// USER
int emulator::setUpEmulator()
{
    DEBUG(3) dprintf("emulator::setUpEmulator() called. this=%p\n", this);

    int retc;

    // Internal module
    int_module = new internal_module();
    if(!int_module)
        return ENOMEM;

    retc = int_module->init();
    if(retc)
        return retc;

    // Exec module
    exec_module = new exec::main();
    if(!exec_module)
        return ENOMEM;

    retc = exec_module->init();
    if(retc)
        return retc;

    // Dos module
    dos_module = new dos::main();
    if(!dos_module)
        return ENOMEM;

    retc = dos_module->init();
    if(retc)
        return retc;

    // Bootstrap
    bootstrap_mapping = new rom_mapping(sizeof(bootstrap_data), bootstrap_data);
    if(!bootstrap_mapping)
        return ENOMEM;

    if(v_space.add_mapping(bootstrap_mapping) == 0xFFFFFFFF)
        return ENOMEM;

    // Spawn emulation process
    char this_hex[17];
    sprintf(this_hex, "%p", this);

    // Set environment variable with "this" pointer.
    // It is inherited by the new process
    if(!SetVar("EMUMIGA_CREATOR", this_hex, -1, GVF_LOCAL_ONLY))
        return ENOMEM;

    creatorProc = (struct Process *)FindTask(0);
    creatorSigNo = AllocSignal(-1);

    if(creatorSigNo == -1)
        return ENOMEM;

    SetSignal(0, 1 << creatorSigNo);

    struct TagItem tags[] = {
        { NP_Entry, (IPTR)processEntry },
        { TAG_DONE, 0 }
    };

    struct Process *new_proc = CreateNewProcTagList(tags);

    if(!new_proc) {
        FreeSignal(creatorSigNo);
        return ENOMEM;
    }

    Wait(1 << creatorSigNo);

    FreeSignal(creatorSigNo);

    DeleteVar("EMUMIGA_CREATOR", GVF_LOCAL_ONLY);

    return 0;
}