Пример #1
0
void Multiboot_Startup(uint32_t pMultibootMagic, MultibootHeader* pMultibootHeader)
{
    if (pMultibootMagic != MULTIBOOT_MAGIC) Halt();
    gMultiboot_CommandLine = (const char*)pMultibootHeader->CommandLine;

    extern char __SOK;
    extern char __EOK;
	extern char gStack;
	extern size_t gStackSize;
	size_t kernelStart = (size_t)&__SOK;
	size_t kernelEnd = (size_t)&__EOK;
	size_t kernelSize = kernelEnd - kernelStart;
	size_t stackStart = (size_t)&gStack;
	size_t stackSize = gStackSize;

	ReservedMemoryBlock reservedMemoryBlocks[RESERVEDMEMORYBLOCK_MAX] = { { kernelStart, kernelSize }, { stackStart, stackSize } };
	uint8_t reservedMemoryBlockCount = 2;

    MultibootModule* module = pMultibootHeader->Modules;
    uint32_t moduleCount = pMultibootHeader->ModulesCount;

	for (uint32_t moduleIndex = 0; moduleIndex < moduleCount; ++moduleIndex, ++module)
	{
        gLoadedModules[gLoadedModuleCount].Address = module->Start;
        gLoadedModules[gLoadedModuleCount].Size = module->End - module->Start;
        gLoadedModules[gLoadedModuleCount].Identifier = (const char*)module->Identifier;
        ++gLoadedModuleCount;

		reservedMemoryBlocks[reservedMemoryBlockCount].Address = module->Start;
		reservedMemoryBlocks[reservedMemoryBlockCount].Size = module->End - module->Start;
		++reservedMemoryBlockCount;
	}

    MultibootMemoryMap* memoryMap = pMultibootHeader->MemoryMaps;
    uint32_t memoryMapCount = pMultibootHeader->MemoryMapsSize / sizeof(MultibootMemoryMap);
	gMemoryBlockCount = 0;
	for (uint32_t memoryMapIndex = 0; memoryMapIndex < memoryMapCount; ++memoryMapIndex, ++memoryMap)
	{
		if (memoryMap->Type == MULTIBOOT_MEMORYMAP_TYPE_AVAILABLE && memoryMap->AddressLower >= MULTIBOOT_MEMORYMAP_LOWER_MEMORY_SIZE)
		{
			gMemoryBlocks[gMemoryBlockCount].Address = memoryMap->AddressLower;
			gMemoryBlocks[gMemoryBlockCount].Size = memoryMap->LengthLower;
			gMemoryBlocks[gMemoryBlockCount].Used = 0;
			gMemoryBlocks[gMemoryBlockCount].Reserved = 0;
			++gMemoryBlockCount;
		}
	}

	ReservedMemoryBlock* reservedMemoryBlock = reservedMemoryBlocks;
	for (uint32_t reservedMemoryBlockIndex = 0; reservedMemoryBlockIndex < reservedMemoryBlockCount; ++reservedMemoryBlockIndex, ++reservedMemoryBlock)
	{
		MemoryBlock* memoryBlock = gMemoryBlocks;
		for (uint32_t memoryBlockIndex = 0; memoryBlockIndex < gMemoryBlockCount; ++memoryBlockIndex, ++memoryBlock)
		{
			if (reservedMemoryBlock->Address + reservedMemoryBlock->Size > memoryBlock->Address &&
				reservedMemoryBlock->Address < memoryBlock->Address + memoryBlock->Size)
			{
				if (reservedMemoryBlock->Address > memoryBlock->Address &&
					reservedMemoryBlock->Address + reservedMemoryBlock->Size >= memoryBlock->Address + memoryBlock->Size)
				{
					// Space left at start, but not at end
					memoryBlock->Size = reservedMemoryBlock->Address - memoryBlock->Address;
				}
				else if (reservedMemoryBlock->Address <= memoryBlock->Address &&
							reservedMemoryBlock->Address + reservedMemoryBlock->Size < memoryBlock->Address + memoryBlock->Size)
				{
					// Space left at end, but not at start
					memoryBlock->Size = (memoryBlock->Address + memoryBlock->Size) - (reservedMemoryBlock->Address + reservedMemoryBlock->Size);
					memoryBlock->Address = reservedMemoryBlock->Address + reservedMemoryBlock->Size;
				}
				else if (reservedMemoryBlock->Address > memoryBlock->Address &&
							reservedMemoryBlock->Address + reservedMemoryBlock->Size < memoryBlock->Address + memoryBlock->Size)
				{
					// Space left at both start and end
					if (gMemoryBlockCount == MEMORYBLOCK_MAX) Panic("Insufficient memory blocks to process available memory");

					for (uint32_t copyBlockIndex = gMemoryBlockCount; copyBlockIndex > memoryBlockIndex; --copyBlockIndex)
					{
						gMemoryBlocks[copyBlockIndex] = gMemoryBlocks[copyBlockIndex - 1];
					}
					++gMemoryBlockCount;
						
					gMemoryBlocks[memoryBlockIndex + 1].Size = (memoryBlock->Address + memoryBlock->Size) - (reservedMemoryBlock->Address + reservedMemoryBlock->Size);
					gMemoryBlocks[memoryBlockIndex + 1].Address = reservedMemoryBlock->Address + reservedMemoryBlock->Size;
					memoryBlock->Size = reservedMemoryBlock->Address - memoryBlock->Address;
						
				}
				else
				{
					// No space, used the whole darn block!
					for (uint32_t copyBlockIndex = memoryBlockIndex + 1; copyBlockIndex < gMemoryBlockCount; ++copyBlockIndex)
					{
						gMemoryBlocks[copyBlockIndex - 1] = gMemoryBlocks[copyBlockIndex];
					}
					--gMemoryBlockCount;
				}
			}
		}
	}
	if (gMemoryBlockCount == 0) Panic("There is no memory blocks available");
}
Пример #2
0
Bool
FileIO_AtomicUpdate(FileIODescriptor *newFD,   // IN/OUT: file IO descriptor
                    FileIODescriptor *currFD)  // IN/OUT: file IO descriptor
{
   char *currPath = NULL;
   char *newPath = NULL;
#if defined(_WIN32)
   uint32 currAccess;
   uint32 newAccess;
   FileIOResult status;
   FileIODescriptor tmpFD;
#else
   int fd;
#endif
   int savedErrno = 0;
   Bool ret = FALSE;

   ASSERT(FileIO_IsValid(newFD));
   ASSERT(FileIO_IsValid(currFD));

   if (HostType_OSIsVMK()) {
#if defined(VMX86_SERVER)
      FS_SwapFilesArgs *args = NULL;
      char *dirName = NULL;
      char *fileName = NULL;
      char *dstDirName = NULL;
      char *dstFileName = NULL;

      currPath = File_FullPath(FileIO_Filename(currFD));
      if (!currPath) {
         savedErrno = errno;
         Log("%s: File_FullPath of '%s' failed.\n", __FUNCTION__,
             FileIO_Filename(currFD));
         goto swapdone;
      }

      newPath = File_FullPath(FileIO_Filename(newFD));
      if (!newPath) {
         savedErrno = errno;
         Log("%s: File_FullPath of '%s' failed.\n", __FUNCTION__,
             FileIO_Filename(newFD));
         goto swapdone;
      }

      File_GetPathName(newPath, &dirName, &fileName);
      File_GetPathName(currPath, &dstDirName, &dstFileName);

      ASSERT(dirName);
      ASSERT(fileName && *fileName);
      ASSERT(dstDirName);
      ASSERT(dstFileName && *dstFileName);
      ASSERT(File_IsSameFile(dirName, dstDirName));

      args = Util_SafeCalloc(1, sizeof *args);
      if (Str_Snprintf(args->srcFile, sizeof args->srcFile, "%s",
                       fileName) < 0) {
         Log("%s: Path too long \"%s\".\n", __FUNCTION__, fileName);
         savedErrno = ENAMETOOLONG;
         goto swapdone;
      }
      if (Str_Snprintf(args->dstFilePath, sizeof args->dstFilePath, "%s/%s",
                       dstDirName, dstFileName) < 0) {
         Log("%s: Path too long \"%s\".\n", __FUNCTION__, dstFileName);
         savedErrno = ENAMETOOLONG;
         goto swapdone;
      }

      /*
       * Issue the ioctl on the directory rather than on the file,
       * because the file could be open.
       */

      if (!*dirName) {
         /* need a proper root directory string for Posix_Open() */
         free(dirName);
         dirName = Util_SafeStrdup("/");
      }

      fd = Posix_Open(dirName, O_RDONLY);
      if (fd < 0) {
         Log("%s: Open failed \"%s\" %d.\n", __FUNCTION__, dirName, errno);
         ASSERT(errno != EBUSY);   /* #615124. */
         savedErrno = errno;
         goto swapdone;
      }

      if (ioctl(fd, IOCTLCMD_VMFS_SWAP_FILES, args) != 0) {
         savedErrno = errno;
         if (errno != ENOSYS && errno != ENOTTY) {
            Log("%s: ioctl failed %d.\n", __FUNCTION__, errno);
            ASSERT(errno != EBUSY);   /* #615124. */
         }
      } else {
         ret = TRUE;
      }

      close(fd);

      /*
       * Did we fail because we are on a file system that does not
       * support the IOCTLCMD_VMFS_SWAP_FILES ioctl? If so fallback to
       * using rename.
       *
       * Check for both ENOSYS and ENOTTY. PR 957695
       */
      if (savedErrno == ENOSYS || savedErrno == ENOTTY) {
         /*
          * NFS allows renames of locked files, even if both files
          * are locked.  The file lock follows the file handle, not
          * the name, so after the rename we can swap the underlying
          * file descriptors instead of closing and reopening the
          * target file.
          *
          * This is different than the hosted path below because
          * ESX uses native file locks and hosted does not.
          *
          * We assume that all ESX file systems that support rename
          * have the same file lock semantics as NFS.
          */

         if (File_Rename(newPath, currPath)) {
            Log("%s: rename of '%s' to '%s' failed %d.\n",
                __FUNCTION__, newPath, currPath, errno);
            savedErrno = errno;
            goto swapdone;
         }
         ret = TRUE;
         fd = newFD->posix;
         newFD->posix = currFD->posix;
         currFD->posix = fd;
         FileIO_Close(newFD);
      }

swapdone:
      free(args);
      free(dirName);
      free(fileName);
      free(dstDirName);
      free(dstFileName);
      free(currPath);
      free(newPath);

      errno = savedErrno;
      return ret;
#else
      NOT_REACHED();
#endif
   }
#if defined(_WIN32)
   currPath = Unicode_Duplicate(FileIO_Filename(currFD));
   newPath = Unicode_Duplicate(FileIO_Filename(newFD));

   newAccess = newFD->flags;
   currAccess = currFD->flags;

   FileIO_Close(newFD);

   /*
    * The current file needs to be closed and reopened,
    * but we don't want to drop the file lock by calling
    * FileIO_Close() on it.  Instead, use native close primitives.
    * We'll reopen it later with FileIO_Open.  Set the
    * descriptor/handle to an invalid value while we're in the
    * middle of transferring ownership.
    */

   CloseHandle(currFD->win32);
   currFD->win32 = INVALID_HANDLE_VALUE;
   if (File_RenameRetry(newPath, currPath, 10) == 0) {
      ret = TRUE;
   } else {
      savedErrno = errno;
      ASSERT(!ret);
   }

   FileIO_Invalidate(&tmpFD);

   /*
    * Clear the locking bits from the requested access so that reopening
    * the file ignores the advisory lock.
    */

   ASSERT((currAccess & FILEIO_OPEN_LOCK_MANDATORY) == 0);
   currAccess &= ~(FILEIO_OPEN_LOCK_MANDATORY | FILEIO_OPEN_LOCK_ADVISORY |
                   FILEIO_OPEN_LOCK_BEST | FILEIO_OPEN_LOCKED);
   status = FileIO_Open(&tmpFD, currPath, currAccess, FILEIO_OPEN);
   if (!FileIO_IsSuccess(status)) {
      Panic("Failed to reopen dictionary after renaming "
            "\"%s\" to \"%s\": %s (%d)\n", newPath, currPath,
            FileIO_ErrorEnglish(status), status);
   }
   ASSERT(tmpFD.lockToken == NULL);

   currFD->win32 = tmpFD.win32;

   FileIO_Cleanup(&tmpFD);
   free(currPath);
   free(newPath);
   errno = savedErrno;

   return ret;
#else
   currPath = (char *)FileIO_Filename(currFD);
   newPath = (char *)FileIO_Filename(newFD);

   if (File_Rename(newPath, currPath)) {
      Log("%s: rename of '%s' to '%s' failed %d.\n",
          __FUNCTION__, newPath, currPath, errno);
          savedErrno = errno;
   } else {
      ret = TRUE;
      fd = newFD->posix;
      newFD->posix = currFD->posix;
      currFD->posix = fd;
      FileIO_Close(newFD);
   }

   errno = savedErrno;

   return ret;
#endif
}
Пример #3
0
void CGridImg::UpdateSelectedRegion(TInt aSelectCount,TUint aMoveFlags)
	{
	//
	// Updates the latest selected region in accordance with the passed parameters.
	//
	__ASSERT_DEBUG(aSelectCount>0,Panic(ECellRegionNothingSelected));

	TRangeRef range = (*iSelected)[aSelectCount-1];
	TRangeRef bounds(iGridLay->GridRange());
	if (aMoveFlags&EIsAbsoluteMove)
		{
		if (((aMoveFlags&(EIsColumnSelected|EIsRowSelected|EIsWithDrag))==EIsColumnSelected)
			|| (iSelected->IsColSelectedLastIndex(iCursorPos.iCol) && (aMoveFlags&EIsWithDrag)
			&& !iSelected->IsRowSelectedLastIndex(iCursorPos.iRow)))
			{
			iGridLay->LimitCell(iNewCursorPos);
			range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol);
			range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol);
			range.iFrom.iRow = bounds.iFrom.iRow;
			range.iTo.iRow = bounds.iTo.iRow;
			iCursorPos.iCol = iNewCursorPos.iCol;
			iNewCursorPos.iRow = iCursorPos.iRow;
			}
		else if (((aMoveFlags&(EIsRowSelected|EIsColumnSelected|EIsWithDrag))==EIsRowSelected)
			|| (iSelected->IsRowSelectedLastIndex(iCursorPos.iRow) && (aMoveFlags&EIsWithDrag)
			&& !iSelected->IsColSelectedLastIndex(iCursorPos.iCol)))
			{
			iGridLay->LimitCell(iNewCursorPos);
			range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow);
			range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow);
			range.iFrom.iCol = bounds.iFrom.iCol;
			range.iTo.iCol = bounds.iTo.iCol;
			iCursorPos.iRow = iNewCursorPos.iRow;
			iNewCursorPos.iCol = iCursorPos.iCol;
			}
		else if ((aMoveFlags&(EIsRowSelected|EIsColumnSelected|EIsWithDrag))==
			(EIsRowSelected|EIsColumnSelected))
			{
			range = bounds;
			iNewCursorPos = iCursorPos = bounds.iTo;
			}
		else if (!(iSelected->IsRangeSelectedLastIndex(iGridLay->GridRange()) &&
			(aMoveFlags&EIsWithDrag)))
			{
			iGridLay->LimitCell(iNewCursorPos);
 			range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol);
			range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol);
   			range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow);
			range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow);
			iCursorPos = iNewCursorPos;
			}
		}
	else
		{
		if (iNewCursorPos.iRow != iCursorPos.iRow)
			{
 			range.iFrom.iRow = Min(iAnchorPos.iRow, iNewCursorPos.iRow);
			range.iTo.iRow = Max(iAnchorPos.iRow, iNewCursorPos.iRow);
			iCursorPos.iRow = iNewCursorPos.iRow;
			}
		if (iNewCursorPos.iCol != iCursorPos.iCol && !iGridLay->IsRowPermanentlySelected())
			{
 			range.iFrom.iCol = Min(iAnchorPos.iCol, iNewCursorPos.iCol);
			range.iTo.iCol = Max(iAnchorPos.iCol, iNewCursorPos.iCol);
			iCursorPos.iCol = iNewCursorPos.iCol;
			}
		}
	iSelected->SetLastCellRange(range);
	}
Пример #4
0
void InputFile::WriteSyms (FILE*) {
    Panic("InputFile::WriteSyms");
}
Пример #5
0
TInt CWin32SocketWrapper::RunError(TInt /*aError*/)
	{
	__ASSERT_DEBUG(EFalse, Panic(EWinSockPrtSocketWrapperUnexpectedRunError));
	return 0;
	}
Пример #6
0
void CWordStyleGallery::StyleL(TInt aControlId)
	{	
	TInt index=ListBoxCurrentItem(EWordCidStyleNameList);			   
	CParagraphStyle* paraStyle=NULL;
	CEikDialog* dialog=NULL;
	TBool normal=EFalse;
	TChar newHotkey=KNoHotkey;
	if (aControlId==EWordCidAddStyle)
		{
		paraStyle=CParagraphStyle::NewL(*(iData.iText.GlobalParaFormatLayer()),*(iData.iText.GlobalCharFormatLayer()));
		dialog=new(ELeave) CWordStyleFormatDialog(iNormalName,iData.iNormalStyleHotKey,iData.iStyleList,
									aControlId,iData.iText,&iData.iPrintSetup,iData.iHotKeyList,newHotkey,paraStyle);
		}
	else
		{
		if ((*iStyleNameList)[index]==iNormalName)
			{
			normal=ETrue;
			dialog=new(ELeave) CWordStyleFormatDialog(iNormalName,iData.iNormalStyleHotKey,iData.iStyleList,
									aControlId,iData.iText,&iData.iPrintSetup,iData.iHotKeyList,newHotkey,NULL,normal);
			}
		else
			{
			paraStyle=iData.iStyleList.PtrByName((*iStyleNameList)[index])->iStyle;
			dialog=new(ELeave) CWordStyleFormatDialog(iNormalName,iData.iNormalStyleHotKey,iData.iStyleList,
									aControlId,iData.iText,&iData.iPrintSetup,iData.iHotKeyList,newHotkey,paraStyle);
			}
		if (normal)
			newHotkey=iData.iNormalStyleHotKey;
		else
			{
			TInt ii=iData.iStyleList.IndexByPtr(paraStyle);
			__ASSERT_DEBUG(ii!=KErrNotFound,Panic(EStyleIntegrityError));
			newHotkey=iData.iHotKeyList[ii];
			}
		}
	//
	if (dialog->ExecuteLD(R_WORD_DIALOG_STYLE_FORMAT))
		{
		SetTextForCancelButtonL();	
		// remove the hotkey from any old style if it has been re-assigned
		if (newHotkey==iData.iNormalStyleHotKey)
			iData.iNormalStyleHotKey=0;
		else
			{
			TInt hotkeyCount=iData.iHotKeyList.Count();
			for (TInt ii=0;ii<hotkeyCount;ii++)
				{
				if (newHotkey==iData.iHotKeyList[ii] && newHotkey!=KNoHotkey)
					{
					iData.iHotKeyList[ii]=0;
					break;
					}					
				}
			}
		//
		if (aControlId==EWordCidAddStyle)
			{
			RParagraphStyleInfo styleSet(paraStyle);
			iData.iStyleList.AppendL(&styleSet);
			}
		else
			{
			iStyleNameList->Delete(index);
			iStyleNameKeyList->Delete(index);
			}
		if (normal)
			iStyleNameList->AppendL(iNormalName);
		else
			iStyleNameList->AppendL(paraStyle->iName);
		iStyleNameList->Sort();
		//
		TParagraphStyleName name=(normal) ? iNormalName : paraStyle->iName;
		for (TInt ii=0;ii<iStyleNameList->Count();ii++)
			{
			if (name==(*iStyleNameList)[ii])
				{
				index=ii;
				break;
				}
			}

		if (aControlId==EWordCidAddStyle)
			iData.iHotKeyList.AppendL(newHotkey);
		else
			{
			if (normal)
				iData.iNormalStyleHotKey=newHotkey;
			else
				{
				CParagraphStyle* style=iData.iStyleList.PtrByName((*iStyleNameList)[index])->iStyle;
				TInt offset=iData.iStyleList.IndexByPtr(style);
				iData.iHotKeyList[offset]=newHotkey;
				}
			}
		MergeArraysL();
		ListBox()->HandleItemAdditionL();
		ListBox()->SetCurrentItemIndexAndDraw(index);
		StyleDescriptionL(index);
		SetDeleteButton();
		}
	else
		{
		if (aControlId==EWordCidAddStyle)
			delete paraStyle;
		}
	}
Пример #7
0
void InputFile::Reread () {
    Panic("InputFile::Reread");
}
Пример #8
0
void CWin32SubSession::Complete(TWin32Message*& aMessage, TInt aReason) const
	{
	__ASSERT_DEBUG(aMessage, Panic(EWinSockPrtSubSessionInvalidMessage));
	aMessage->Complete(aReason);
	aMessage = NULL;
	}
Пример #9
0
void
sched()
{
  struct event *ev;
  fd_set r, w, *set;
  struct event *timeoutev = 0;
  struct timeval timeout;
  int nsel;

  for (;;)
    {
      if (calctimeout)
	timeoutev = calctimo();
      if (timeoutev)
	{
	  gettimeofday(&timeout, NULL);
	  /* tp - timeout */
	  timeout.tv_sec = timeoutev->timeout.tv_sec - timeout.tv_sec;
	  timeout.tv_usec = timeoutev->timeout.tv_usec - timeout.tv_usec;
	  if (timeout.tv_usec < 0)
	    {
	      timeout.tv_usec += 1000000;
	      timeout.tv_sec--;
	    }
	  if (timeout.tv_sec < 0)
	    {
	      timeout.tv_usec = 0;
	      timeout.tv_sec = 0;
	    }
	}
#ifdef DEBUG
      debug("waiting for events");
      if (timeoutev)
        debug2(" timeout %d secs %d usecs", timeout.tv_sec, timeout.tv_usec);
      debug(":\n");
      for (ev = evs; ev; ev = ev->next)
        debug3(" - fd %d type %d pri %d\n", ev->fd, ev->type, ev->pri);
      if (tevs)
        debug("timed events:\n");
      for (ev = tevs; ev; ev = ev->next)
        debug3(" - pri %d sec %d usec %d\n", ev->pri, ev->timeout.tv_sec, ev->timeout.tv_usec);
#endif

      FD_ZERO(&r);
      FD_ZERO(&w);
      for (ev = evs; ev; ev = ev->next)
        {
	  if (ev->condpos && *ev->condpos <= (ev->condneg ? *ev->condneg : 0))
	    {
	      debug2(" - cond ev fd %d type %d failed\n", ev->fd, ev->type);
	      continue;
	    }
	  if (ev->type == EV_READ)
	    FD_SET(ev->fd, &r);
	  else if (ev->type == EV_WRITE)
	    FD_SET(ev->fd, &w);
        }

#ifdef DEBUG
      debug("readfds:");
      for (nsel = 0; nsel < FD_SETSIZE; nsel++)
	if (FD_ISSET(nsel, &r))
	  debug1(" %d", nsel);
      debug("\n");
      debug("writefds:");
      for (nsel = 0; nsel < FD_SETSIZE; nsel++)
	if (FD_ISSET(nsel, &w))
	  debug1(" %d", nsel);
      debug("\n");
#endif

      nsel = select(FD_SETSIZE, &r, &w, (fd_set *)0, timeoutev ? &timeout : (struct timeval *) 0);
      if (nsel < 0)
	{
	  if (errno != EINTR)
	    {
#if defined(sgi) && defined(SVR4)
	      if (errno == EIO && sgihack())
		continue;
#endif
#if defined(__osf__) || defined(M_UNIX)
	      /* OSF/1 3.x, SCO bug: EBADF */
	      /* OSF/1 4.x bug: EIO */
	      if ((errno == EIO || errno == EBADF) && sgihack())
		continue;
#endif
	      Panic(errno, "select");
	    }
	  nsel = 0;
	}
      else if (nsel == 0)	/* timeout */
	{
	  debug("TIMEOUT!\n");
	  ASSERT(timeoutev);
	  evdeq(timeoutev);
	  timeoutev->handler(timeoutev, timeoutev->data);
	}
#ifdef SELECT_BROKEN
      /*
       * Sequents select emulation counts a descriptor which is
       * readable and writeable only as one hit. Waaaaa.
       */
      if (nsel)
        nsel = 2 * FD_SETSIZE;
#endif

      for (ev = evs; ev; ev = nextev)
        {
          nextev = ev->next;
	  if (ev->type != EV_ALWAYS)
	    {
	      set = ev->type == EV_READ ? &r : &w;
	      if (nsel == 0 || !FD_ISSET(ev->fd, set))
		continue;
	      nsel--;
	    }
	  if (ev->condpos && *ev->condpos <= (ev->condneg ? *ev->condneg : 0))
	    continue;
	  debug2(" + hit ev fd %d type %d!\n", ev->fd, ev->type);
	  ev->handler(ev, ev->data);
        }
    }
}
Пример #10
0
EXPORT_C void HelloTraceExample::PanicTrace()
    {
    OstTrace0( TRACE_EXAMPLE, HELLOTRACEEXAMPLE_PANIC, "*********************************************** " );

    Panic(EHelloTraceDllExamplePanic);
    }
Пример #11
0
// from CServProviderBase - the saps will not do all of these
void CBTBasebandSAP::Start()
	{
	LOG_FUNC
	Panic(EBTBaseSAPUnimplementedEvent);
	}
Пример #12
0
// -----------------------------------------------------------------------------
// RMce::Send
// From MMceItc
// -----------------------------------------------------------------------------
//
TInt RMce::Send (TMceItcFunctions aFunction, TIpcArgs& aArgs)
	{
	__ASSERT_ALWAYS (iConnected, Panic( KErrCouldNotConnect ));

	return SendReceive (aFunction, aArgs);
	}
Пример #13
0
/*
 * this will be called twice:
 * 1) rcfilename = "/etc/screenrc"
 * 2) rcfilename = RcFileName
 */
int StartRc(char *rcfilename, int nopanic)
{
	int argc, len;
	char *p, *cp;
	char buf[2048];
	char *args[MAXARGS];
	int argl[MAXARGS];
	FILE *fp;
	char *oldrc_name = rc_name;

	/* always fix termcap/info capabilities */
	extra_incap = CatExtra("TF", extra_incap);

	/* Special settings for vt100 and others */
	if (display && (!strncmp(D_termname, "vt", 2) || !strncmp(D_termname, "xterm", 5)))
		extra_incap =
		    CatExtra
		    ("xn:f0=\033Op:f1=\033Oq:f2=\033Or:f3=\033Os:f4=\033Ot:f5=\033Ou:f6=\033Ov:f7=\033Ow:f8=\033Ox:f9=\033Oy:f.=\033On:f,=\033Ol:fe=\033OM:f+=\033Ok:f-=\033Om:f*=\033Oj:f/=\033Oo:fq=\033OX",
		     extra_incap);

	rc_name = findrcfile(rcfilename);

	if (rc_name == NULL || (fp = secfopen(rc_name, "r")) == NULL) {
		const char *rc_nonnull = rc_name ? rc_name : rcfilename;
		if (!rc_recursion && RcFileName && !strcmp(RcFileName, rc_nonnull)) {
			/*
			 * User explicitly gave us that name,
			 * this is the only case, where we get angry, if we can't read
			 * the file.
			 */
			if (!nopanic)
				Panic(0, "Unable to open \"%s\".", rc_nonnull);
			/* possibly NOTREACHED */
		}
		if (rc_name)
			Free(rc_name);
		rc_name = oldrc_name;
		return 1;
	}
	while (fgets(buf, sizeof buf, fp) != NULL) {
		if ((p = strrchr(buf, '\n')) != NULL)
			*p = '\0';
		if ((argc = Parse(buf, sizeof buf, args, argl)) == 0)
			continue;
		if (strcmp(args[0], "echo") == 0) {
			if (!display)
				continue;
			if (argc < 2 || (argc == 3 && strcmp(args[1], "-n")) || argc > 3) {
				Msg(0, "%s: 'echo [-n] \"string\"' expected.", rc_name);
				continue;
			}
			AddStr(args[argc - 1]);
			if (argc != 3) {
				AddStr("\r\n");
				Flush(0);
			}
		} else if (strcmp(args[0], "sleep") == 0) {
			if (!display)
				continue;
			if (argc != 2) {
				Msg(0, "%s: sleep: one numeric argument expected.", rc_name);
				continue;
			}
			DisplaySleep1000(1000 * atoi(args[1]), 1);
		}
		else if (!strcmp(args[0], "termcapinfo") || !strcmp(args[0], "terminfo"))
		{
			if (!display)
				continue;
			if (argc < 3 || argc > 4) {
				Msg(0, "%s: %s: incorrect number of arguments.", rc_name, args[0]);
				continue;
			}
			for (p = args[1]; p && *p; p = cp) {
				if ((cp = strchr(p, '|')) != 0)
					*cp++ = '\0';
				len = strlen(p);
				if (p[len - 1] == '*') {
					if (!(len - 1) || !strncmp(p, D_termname, len - 1))
						break;
				} else if (!strcmp(p, D_termname))
					break;
			}
			if (!(p && *p))
				continue;
			extra_incap = CatExtra(args[2], extra_incap);
			if (argc == 4)
				extra_outcap = CatExtra(args[3], extra_outcap);
		} else if (!strcmp(args[0], "source")) {
			if (rc_recursion <= 10) {
				rc_recursion++;
				(void)StartRc(args[1], 0);
				rc_recursion--;
			}
		}
	}
	fclose(fp);
	Free(rc_name);
	rc_name = oldrc_name;
	return 0;
}
Пример #14
0
static void
CheckMaxSize(int wi)
{
  unsigned char *oldnull = null;
  unsigned char *oldblank = blank;
  struct win *p;
  int i;
  struct mline *ml;

  wi = ((wi + 1) + 255) & ~255;
  if (wi <= maxwidth)
    return;
  maxwidth = wi;
  debug1("New maxwidth: %d\n", maxwidth);
  blank = (unsigned char *)xrealloc((char *)blank, maxwidth);
  null = (unsigned char *)xrealloc((char *)null, maxwidth);
  mline_old.image = (unsigned char *)xrealloc((char *)mline_old.image, maxwidth);
  mline_old.attr = (unsigned char *)xrealloc((char *)mline_old.attr, maxwidth);
  mline_old.font = (unsigned char *)xrealloc((char *)mline_old.font, maxwidth);
  mline_old.color = (unsigned char *)xrealloc((char *)mline_old.color, maxwidth);
  mline_old.colorx = (unsigned char *)xrealloc((char *)mline_old.colorx, maxwidth);
  if (!(blank && null && mline_old.image && mline_old.attr && mline_old.font && mline_old.color && mline_old.colorx))
    Panic(0, "%s", strnomem);

  MakeBlankLine(blank, maxwidth);
  memset((char *)null, 0, maxwidth);

  mline_blank.image = blank;
  mline_blank.attr  = null;
  mline_null.image = null;
  mline_null.attr  = null;
  mline_blank.font  = null;
  mline_null.font  = null;
  mline_blank.color = null;
  mline_null.color = null;
  mline_blank.colorx = null;
  mline_null.colorx = null;

#define RESET_AFC(x, bl) { if (x == old##bl) x = bl; }

#define RESET_LINES(lines, count) \
  { \
    ml = lines; \
    for (i = 0; i < count; i++, ml++) \
      { \
	RESET_AFC(ml->image, blank); \
	RESET_AFC(ml->attr, null); \
	RESET_AFC(ml->font, null); \
	RESET_AFC(ml->color, null); \
	RESET_AFC(ml->colorx, null); \
      } \
  }

  /* We have to run through all windows to substitute
   * the null and blank references.
   */
  for (p = windows; p; p = p->w_next)
    {
      RESET_LINES(p->w_mlines, p->w_height);

      RESET_LINES(p->w_hlines, p->w_histheight);
      RESET_LINES(p->w_alt.hlines, p->w_alt.histheight);

      RESET_LINES(p->w_alt.mlines, p->w_alt.height);
    }
}
Пример #15
0
// Invoked when injured by something
// NOTE: We dont want to directly call Attack() here, or the bots will have super-human reaction times when injured
BOOL CCSBot::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType)
{
	CBaseEntity *pAttacker = GetClassPtr<CCSEntity>((CBaseEntity *)pevInflictor);

	// if we were attacked by a teammate, rebuke
	if (pAttacker->IsPlayer())
	{
		CBasePlayer *pPlayer = static_cast<CBasePlayer *>(pAttacker);
		if (BotRelationship(pPlayer) == BOT_TEAMMATE && !pPlayer->IsBot())
		{
			GetChatter()->FriendlyFire();
		}

		if (IsEnemy(pPlayer))
		{
			// Track previous attacker so we don't try to panic multiple times for a shotgun blast
			CBasePlayer *lastAttacker = m_attacker;
			float lastAttackedTimestamp = m_attackedTimestamp;

			// keep track of our last attacker
			m_attacker = pPlayer;
			m_attackedTimestamp = gpGlobals->time;

			// no longer safe
			AdjustSafeTime();

			if (!IsSurprised() && (m_attacker != lastAttacker || m_attackedTimestamp != lastAttackedTimestamp))
			{
				// being hurt by an enemy we can't see causes panic
				if (!IsVisible(pPlayer, CHECK_FOV))
				{
					bool bPanic = false;

					// if not attacking anything, look around to try to find attacker
					if (!IsAttacking())
					{
						bPanic = true;
					}
					else
					{
						// we are attacking
						if (!IsEnemyVisible())
						{
							// can't see our current enemy, panic to acquire new attacker
							bPanic = true;
						}
					}

					if (!bPanic)
					{
						float invSkill = 1.0f - GetProfile()->GetSkill();
						float panicChance = invSkill * invSkill * 50.0f;

						if (panicChance > RANDOM_FLOAT(0, 100))
						{
							bPanic = true;
						}
					}

					if (bPanic)
					{
						// can't see our current enemy, panic to acquire new attacker
						Panic(m_attacker);
					}
				}
			}
		}
	}

	// extend
	return CBasePlayer::TakeDamage(pevInflictor, pevAttacker, flDamage, bitsDamageType);
}
Пример #16
0
TInt E32Main()
	{
	StaticMain();
	
	RBuf cmd;
	test_KErrNone(cmd.Create(User::CommandLineLength()));
	User::CommandLine(cmd);

	TLex lex(cmd);
	TTestType type;
	test_KErrNone(lex.Val((TInt&)type));
	GlobalObjectWithDestructor.iTestType = type;

	RMsgQueue<TMessage> messageQueue;
	test_KErrNone(messageQueue.OpenGlobal(KMessageQueueName));

	// Dynamically load DLL with global data
	RLibrary library;
	test_KErrNone(library.Load(KDynamicDll));
	
	switch(type)
		{
		case ETestMainThreadReturn:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			return type;

		case ETestMainThreadExit:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			User::Exit(type);
			break;

		case ETestChildThreadReturn:
			{
			// Start child thread passing this thread's id
			MainThreadId = RThread().Id();
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)type));
			TRequestStatus status;
			childThread.Rendezvous(status);
			childThread.Resume();

			User::After(1);

			// Wait for child to open handle on this thread
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();

			// Set this thread non-critical and exit
			User::SetCritical(User::ENotCritical);
			}
			break;

		case ETestOtherThreadExit:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), ExitThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			TRequestStatus status;
			childThread.Logon(status);
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			}
			return type;

		case ETestOtherThreadPanic:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), PanicThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			TRequestStatus status;
			childThread.Logon(status);
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			}
			return type;
			
		case ETestOtherThreadRunning:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), LoopThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			childThread.Close();
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			}
			return type;
			
		case ETestPermanentThreadExit:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), PermanentThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			TRequestStatus status;
			childThread.Logon(status);
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();
			}
			break;
			
		case ETestRecursive:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			break;

		case ETestDestructorExits:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			break;

		case ETestLastThreadPanic:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			Panic(type);
			break;
			
		default:
			test(EFalse);
		}
	return KErrNone;
	}
Пример #17
0
TBool CWordStyleGallery::OkToExitL(TInt aButtonId)
	{
	switch(aButtonId)
		{
		case EWordCidAddStyle:
		case EWordCidModifyStyle:
			StyleL(aButtonId);
			return EFalse;
		case EEikBidDelete:
			{
			if (ButtonGroupContainer().IsCommandDimmed(EEikBidDelete))
				return EFalse;
			TInt index = ListBoxCurrentItem(EWordCidStyleNameList);			   
			TParagraphStyleName name = (*iStyleNameList)[index]; 
			//			
			TBuf<RMessageWindow::EMaxTextLength> title;
			TBuf<RMessageWindow::EMaxTextLength> res;
			iCoeEnv->ReadResource(res, R_WORD_DELETE_STYLE_TITLE);
			title.Format(res, &name);
			//
			if (iEikonEnv->QueryWinL(title, _L("")))
				{// Can never delete the normal style
				CParagraphStyle* paraStyle = iData.iStyleList.PtrByName(name)->iStyle;
				TInt offset = iData.iStyleList.IndexByPtr(paraStyle);
				__ASSERT_ALWAYS(offset >= 0, Panic(EWordGalleryInvalidStyle));
				iData.iText.NotifyStyleDeletedL(paraStyle);
				iData.iStyleList.Remove(paraStyle);
				iStyleNameList->Delete(index);
				iStyleNameKeyList->Delete(index);
				iData.iHotKeyList.Delete(offset);
				ListBox()->Reset();
				if (index == iStyleNameList->Count())
					index = index-KNormalIndex;
				ListBox()->SetCurrentItemIndex(index);
				ListBox()->UpdateScrollBarsL();				  //don't have to this.listbox should provide Handledeleteitem method
				ListBox()->ScrollToMakeItemVisible(index);
				ListBox()->DrawNow();
				SetTextForCancelButtonL();
				iData.iApplyStyle = ETrue;
				}
			SetDeleteButton();
			StyleDescriptionL(index);
			return EFalse;
			}
		case EEikBidOk:
			{
			TInt index = ListBoxCurrentItem(EWordCidStyleNameList);
			MUnifiedEditor::MStyleSupport* style_support = iData.iEditor.StyleSupport();
			if (style_support)
				{
				TPtrC styleName = (*iStyleNameList)[index];
				// normal style name will not be recognised by the editor object,
				// as it is our own invention. A null descriptor should be used.
				const TPtrC nullDes;
				if (styleName == iNormalName)
					styleName.Set(nullDes);
				style_support->SetStyleL(iData.iSelection.LowerPos(), iData.iSelection.Length(), styleName);
				}
			iData.iApplyStyle=ETrue;
			}
		}
	//
	return ETrue;
	}
Пример #18
0
TInt PanicThread(TAny*)
	{
	Panic(KErrNone);
	return KErrNone;
	}
Пример #19
0
/*ARGSUSED*/
int
main(int argc, char *argv[]) {
    XEvent ev;
    XGCValues gv;
    XSetWindowAttributes attr;
    
    (void) argc;
    argv0 = argv[0];
    
    /* Open a connection to the X server. */
    dpy = XOpenDisplay("");
    if (dpy == 0)
        Panic("can't open display.");
    
    get_resources();
    
    /* Find the screen's dimensions. */
    display_width = DisplayWidth(dpy, DefaultScreen(dpy));
    display_height = DisplayHeight(dpy, DefaultScreen(dpy));
    
    /* Set up an error handler. */
    XSetErrorHandler(ErrorHandler);
    
    /* Get the pixel values of the only two colours we use. */
    black = BlackPixel(dpy, DefaultScreen(dpy));
    white = WhitePixel(dpy, DefaultScreen(dpy));
    
    /* Get font. */
    font = XLoadQueryFont(dpy, font_name);
    if (font == 0)
        font = XLoadQueryFont(dpy, "fixed");
    if (font == 0)
        Panic("can't find a font.");
    
    /* Get a cursor. */
    initCursor();
    
    /* Create the window. */
    root = DefaultRootWindow(dpy);
    attr.override_redirect = True;
    attr.background_pixel = white;
    attr.border_pixel = black;
    attr.cursor = mouse_cursor;
    attr.event_mask = ExposureMask | VisibilityChangeMask |
        ButtonMotionMask | PointerMotionHintMask |
        ButtonPressMask | ButtonReleaseMask | StructureNotifyMask |
        EnterWindowMask | LeaveWindowMask;
    window = XCreateWindow(dpy, root,
        0, 0,
        display_width, 1.2 * (font->ascent + font->descent),
        0, CopyFromParent, InputOutput, CopyFromParent,
        CWOverrideRedirect | CWBackPixel | CWBorderPixel |
        CWCursor | CWEventMask,
        &attr);
    
    /* Create GC. */
    gv.foreground = black;
    gv.background = white;
    gv.font = font->fid;
    gc = XCreateGC(dpy, window, GCForeground | GCBackground | GCFont,
        &gv);
    
    /* Create the menu items. */
    readMenu();
    
    /* Bring up the window. */
    XMapRaised(dpy, window);
    
    /* Make sure all our communication to the server got through. */
    XSync(dpy, False);
    
    /* The main event loop. */
    for (;;) {
        getEvent(&ev);
        dispatch(&ev);
    }
}
Пример #20
0
void VideoStream::OpenStream()
{
	/* now that all the parameters are set, we can open the 
	   video codecs and allocate the necessary encode buffers */
	if ( ost )
	{
#if ZM_FFMPEG_SVN
		AVCodecContext *c = ost->codec;
#else
		AVCodecContext *c = &ost->codec;
#endif

		/* find the video encoder */
		AVCodec *codec = avcodec_find_encoder(c->codec_id);
		if ( !codec )
		{
			Panic( "codec not found" );
		}

		/* open the codec */
		if ( avcodec_open(c, codec) < 0 )
		{
			Panic( "Could not open codec" );
		}

		/* allocate the encoded raw picture */
		opicture = avcodec_alloc_frame();
		if ( !opicture )
		{
			Panic( "Could not allocate opicture" );
		}
		int size = avpicture_get_size( c->pix_fmt, c->width, c->height);
		uint8_t *opicture_buf = (uint8_t *)malloc(size);
		if ( !opicture_buf )
		{
			av_free(opicture);
			Panic( "Could not allocate opicture" );
		}
		avpicture_fill( (AVPicture *)opicture, opicture_buf, c->pix_fmt, c->width, c->height );

		/* if the output format is not RGB24, then a temporary RGB24
		   picture is needed too. It is then converted to the required
		   output format */
		tmp_opicture = NULL;
		if ( c->pix_fmt != pf )
		{
			tmp_opicture = avcodec_alloc_frame();
			if ( !tmp_opicture )
			{
				Panic( "Could not allocate temporary opicture" );
			}
			int size = avpicture_get_size( pf, c->width, c->height);
			uint8_t *tmp_opicture_buf = (uint8_t *)malloc(size);
			if (!tmp_opicture_buf)
			{
				av_free( tmp_opicture );
				Panic( "Could not allocate temporary opicture" );
			}
			avpicture_fill( (AVPicture *)tmp_opicture, tmp_opicture_buf, pf, c->width, c->height );
		}
	}

	/* open the output file, if needed */
	if ( !(of->flags & AVFMT_NOFILE) )
	{
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1)
		if ( avio_open(&ofc->pb, filename, URL_WRONLY) < 0 )
#else
		if ( url_fopen(&ofc->pb, filename, URL_WRONLY) < 0 )
#endif
		{
			Fatal( "Could not open '%s'", filename );
		}
	}

	video_outbuf = NULL;
	if ( !(ofc->oformat->flags & AVFMT_RAWPICTURE) )
	{
		/* allocate output buffer */
		/* XXX: API change will be done */
		video_outbuf_size = 200000;
		video_outbuf = (uint8_t *)malloc(video_outbuf_size);
	}

	/* write the stream header, if any */
	av_write_header(ofc);
}
Пример #21
0
void InputFile::WriteData (FILE*) {
    Panic("InputFile::WriteData");
}
Пример #22
0
double VideoStream::EncodeFrame( uint8_t *buffer, int buffer_size, bool add_timestamp, unsigned int timestamp )
{
#ifdef HAVE_LIBSWSCALE
    static struct SwsContext *img_convert_ctx = 0;
#endif // HAVE_LIBSWSCALE
	double pts = 0.0;


	if (ost)
	{
#if ZM_FFMPEG_048
		pts = (double)ost->pts.val * ofc->pts_num / ofc->pts_den;
#else
		pts = (double)ost->pts.val * ost->time_base.num / ost->time_base.den;
#endif
	}

#if ZM_FFMPEG_SVN
	AVCodecContext *c = ost->codec;
#else
	AVCodecContext *c = &ost->codec;
#endif
	if ( c->pix_fmt != pf )
	{
		memcpy( tmp_opicture->data[0], buffer, buffer_size );
#ifdef HAVE_LIBSWSCALE
        if ( !img_convert_ctx )
        {
            img_convert_ctx = sws_getCachedContext( NULL, c->width, c->height, pf, c->width, c->height, c->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL );
            if ( !img_convert_ctx )
                Panic( "Unable to initialise image scaling context" );
        }
        sws_scale( img_convert_ctx, tmp_opicture->data, tmp_opicture->linesize, 0, c->height, opicture->data, opicture->linesize );
#else // HAVE_LIBSWSCALE
		img_convert( (AVPicture *)opicture, c->pix_fmt, (AVPicture *)tmp_opicture, pf, c->width, c->height );
#endif // HAVE_LIBSWSCALE
	}
	else
	{
		memcpy( opicture->data[0], buffer, buffer_size );
	}
	AVFrame *opicture_ptr = opicture;

	int ret = 0;
	if ( ofc->oformat->flags & AVFMT_RAWPICTURE )
	{
#if ZM_FFMPEG_048
		ret = av_write_frame( ofc, ost->index, (uint8_t *)opicture_ptr, sizeof(AVPicture) );
#else
		AVPacket pkt;
		av_init_packet( &pkt );

#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1)
		pkt.flags |= AV_PKT_FLAG_KEY;
#else
		pkt.flags |= PKT_FLAG_KEY;
#endif
		pkt.stream_index = ost->index;
		pkt.data = (uint8_t *)opicture_ptr;
		pkt.size = sizeof(AVPicture);

		ret = av_write_frame(ofc, &pkt);
#endif
	}
	else
	{
		if ( add_timestamp )
			ost->pts.val = timestamp;
		int out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, opicture_ptr);
		if ( out_size > 0 )
		{
#if ZM_FFMPEG_048
			ret = av_write_frame(ofc, ost->index, video_outbuf, out_size);
#else
			AVPacket pkt;
			av_init_packet(&pkt);

#if ZM_FFMPEG_049
			pkt.pts = c->coded_frame->pts;
#else
			pkt.pts= av_rescale_q( c->coded_frame->pts, c->time_base, ost->time_base );
#endif
			if(c->coded_frame->key_frame)
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1)
				pkt.flags |= AV_PKT_FLAG_KEY;
#else
				pkt.flags |= PKT_FLAG_KEY;
#endif
			pkt.stream_index = ost->index;
			pkt.data = video_outbuf;
			pkt.size = out_size;

			ret = av_write_frame( ofc, &pkt );
#endif
		}
	}
	if ( ret != 0 )
	{
		Fatal( "Error %d while writing video frame: %s", ret, strerror( errno ) );
	}
	return( pts );
}
Пример #23
0
void InputFile::WriteStrTab (FILE*) {
    Panic("InputFile::WriteStrTab");
}
Пример #24
0
const CASN1EncBase& CASN1EncExplicitTag::Child(const TUint aIndex) const
	{
	__ASSERT_ALWAYS(aIndex == 0, Panic(KErrArgument));

	return *iEncoder;
	}
Пример #25
0
void CWin32Socket::ServiceL(TWin32Message& aMessage)
	{
	switch (aMessage.OppCode())
		{
		case EConnect:
			{
			Connect(aMessage);
			break;
			}
		case ECancelConnect:
			{
			if (iConnectMessage)
				{
				Complete(iConnectMessage, KErrCancel);
				}
			break;
			}
		case ESend:
			{
			Send(aMessage);
			break;
			}
		case ECancelSend:
			{
			if (iSendMessage)
				{
				Complete(iSendMessage, KErrCancel);
				}
			break;
			}
		case ESendTo:
			{
			SendTo(aMessage);
			break;
			}
		case ECancelSendTo:
			{
			if (iSendMessage)
				{
				Complete(iSendMessage, KErrCancel);
				}
			break;
			}
		case EReceive:
			{
			Receive(aMessage);
			break;
			}
		case ECancelReceive:
			{
			if (iReceiveMessage)
				{
				Complete(iReceiveMessage, KErrCancel);
				}
			break;
			}
		case EReceiveFrom:
			{
			ReceiveFrom(aMessage);
			break;
			}
		case ECancelReceiveFrom:
			{
			if (iReceiveMessage)
				{
				Complete(iReceiveMessage, KErrCancel);
				}
			break;
			}
		case EGetSocketName:
			{
			GetSocketName(aMessage);
			break;
			}
		case EBind:
			{
			Bind(aMessage);
			break;
			}
		case EGetPeerName:
			{
			GetPeerName(aMessage);
			break;
			}
		case EListen:
			{
			Listen(aMessage);
			break;
			}
		case EAccept:
			{
			Accept(aMessage);
			break;
			}
		case ECancelAccept:
			{
			if (iAcceptMessage)
				{
				Complete(iAcceptMessage, KErrCancel);
				}
			break;
			}
		case EGetOption:
			{
			GetOption(aMessage);
			break;
			}
		case ESetOption:
			{
			SetOption(aMessage);
			break;
			}
		default:
			{
			__ASSERT_DEBUG(EFalse, Panic(EWinSockPrtInvalidSocketOppCode));
			}
		}
	}
void hfpHandlerConnectCfm( const HFP_SLC_CONNECT_CFM_T *cfm )
{
	theHeadset.slcConnecting = FALSE;
	
    if (stateManagerGetHfpState() == headsetPoweringOn)
    {
        if ( cfm->status == hfp_connect_success )
        {			
            /* A connection has been made and we are now logically off */
			if (cfm->hfp == theHeadset.hfp)
				theHeadset.hfp_hsp = theHeadset.hfp;
    		else
				theHeadset.hfp_hsp = theHeadset.hsp;
   
            hfpSlcDisconnect(); 
        }	
		theHeadset.slcConnectFromPowerOn = FALSE;
        return;
    }
    
    if (cfm->status == hfp_connect_success)
    {      		
        hfpSlcConnectSuccess(cfm->hfp, cfm->sink);
		/* Update Link Policy as HFP has connected. */
		linkPolicySLCconnect();
    }
    else if (cfm->status == hfp_connect_sdp_fail)
    {
        if ( !stateManagerIsHfpConnected() )  /*only continue if not already connected*/
        {
            if (cfm->hfp == theHeadset.hfp)
            {
                /* Didn't find HFP so try HSP */
				if(theHeadset.inquiry_data)
				{
					if (!hfpSlcConnectBdaddrRequest(hfp_headset_profile, &theHeadset.inquiry_data[0].bd_addr))
					{
						/* This connection failed so check if inquiry needs to resume */
						inquiryContinue();
					}
				}
            }
            else if (cfm->hfp == theHeadset.hsp)
            {
                HFP_DEBUG(("SLC: CFM HSP Fail\n")) ;
				/* This connection failed so check if inquiry needs to resume */
				inquiryContinue();
            }
            else
            {
                Panic();/* Unknown profile instance */
            }
        } 
		else
		{			
			theHeadset.slcConnectFromPowerOn = FALSE;
		}
    }
    else
    {
        if ( !stateManagerIsHfpConnected() )  /*only continue if not already connected*/
        {    /* Failed to connect */    
        }
		else
		{			
			theHeadset.slcConnectFromPowerOn = FALSE;
		}
		/* This connection failed so check if inquiry needs to resume */
		inquiryContinue();
    }       
}
int main() {
  crazy_context_t* context = crazy_context_create();

  RelroLibrary foo;

  int pipes[2];
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipes) < 0)
    Panic("Could not create socket pair: %s", strerror(errno));

  pid_t child = fork();
  if (child < 0)
    Panic("Could not fork test program!");

  if (child == 0) {
    // In the child.
    crazy_context_set_load_address(context, CHILD_ADDRESS);
    foo.Init("libfoo_with_relro.so", context);

    printf("Child waiting for foo relro fd\n");

    foo.ReceiveRelroInfo(pipes[0]);
    foo.UseSharedRelro(context);

    printf("RELRO used in child process\n");

    CheckRelroMaps(1);

    FunctionPtr foo_func;
    if (!crazy_library_find_symbol(
             foo.library, "Foo", reinterpret_cast<void**>(&foo_func)))
      Panic("Could not find 'Foo' in library");

    printf("Calling Foo()\n");
    (*foo_func)();

    printf("Foo called, exiting\n");

    exit(0);

  } else {
    // In the parent.

    // Load at fixed address to simplify testing.
    crazy_context_set_load_address(context, PARENT_ADDRESS);
    foo.Init("libfoo_with_relro.so", context);

    printf("Library loaded\n");

    printf("Parent enabling foo RELRO sharing\n");

    foo.CreateSharedRelro(context, CHILD_ADDRESS);
    foo.SendRelroInfo(pipes[1]);

    printf("Relocated RELRO sent to child\n");

    CheckRelroMaps(0);

    printf("Parent waiting for child\n");

    // Wait for child to complete.
    int status;
    waitpid(child, &status, 0);

    if (WIFSIGNALED(status))
      Panic("Child terminated by signal!!\n");
    else if (WIFEXITED(status)) {
      int child_status = WEXITSTATUS(status);
      if (child_status != 0)
        Panic("Child terminated with status=%d\n", child_status);
    } else
      Panic("Child exited for unknown reason!!\n");
  }

  crazy_context_destroy(context);
  return 0;
}
Пример #28
0
static void CheckMaxSize(int wi)
{
    uint32_t *oldnull = null;
    uint32_t *oldblank = blank;
    Window *p;
    int i;
    struct mline *ml;

    if (wi > MAXWIDTH)
        wi = MAXWIDTH;
    if (wi <= maxwidth)
        return;
    maxwidth = wi + 1;
    blank = xrealloc(blank, maxwidth * 4);
    null = xrealloc(null, maxwidth * 4);
    mline_old.image = xrealloc(mline_old.image, maxwidth * 4);
    mline_old.attr = xrealloc(mline_old.attr, maxwidth * 4);
    mline_old.font = xrealloc(mline_old.font, maxwidth * 4);
    mline_old.fontx = xrealloc(mline_old.fontx, maxwidth * 4);
    mline_old.colorbg = xrealloc(mline_old.colorbg, maxwidth * 4);
    mline_old.colorfg = xrealloc(mline_old.colorfg, maxwidth * 4);
    if (!(blank && null && mline_old.image && mline_old.attr && mline_old.font && mline_old.fontx && mline_old.colorbg && mline_old.colorfg))
        Panic(0, "%s", strnomem);

    MakeBlankLine(blank, maxwidth);
    memset(null, 0, maxwidth * 4);

    mline_blank.image = blank;
    mline_blank.attr = null;
    mline_null.image = null;
    mline_null.attr = null;
    mline_blank.font = null;
    mline_null.font = null;
    mline_blank.fontx = null;
    mline_null.fontx = null;
    mline_blank.colorbg = null;
    mline_null.colorbg = null;
    mline_blank.colorfg = null;
    mline_null.colorfg = null;

#define RESET_AFC(x, bl) do { if (x == old##bl) x = bl; } while (0)

#define RESET_LINES(lines, count) \
  do { \
    ml = lines; \
    for (i = 0; i < count; i++, ml++) \
      { \
	RESET_AFC(ml->image, blank); \
	RESET_AFC(ml->attr, null); \
	RESET_AFC(ml->font, null); \
	RESET_AFC(ml->fontx, null); \
	RESET_AFC(ml->colorbg, null); \
	RESET_AFC(ml->colorfg, null); \
      } \
  } while (0)

    /* We have to run through all windows to substitute
     * the null and blank references.
     */
    for (p = windows; p; p = p->w_next) {
        RESET_LINES(p->w_mlines, p->w_height);

        RESET_LINES(p->w_hlines, p->w_histheight);
        RESET_LINES(p->w_alt.hlines, p->w_alt.histheight);

        RESET_LINES(p->w_alt.mlines, p->w_alt.height);
    }
}
Пример #29
0
/*
 * Compile the terminal capabilities for a display.
 * Input: tgetent(, D_termname) extra_incap, extra_outcap.
 * Effect: display initialisation.
 */
int
InitTermcap(int wi, int he)
{
  register char *s;
  int i;
  char tbuf[TERMCAP_BUFSIZE], *tp;
  int t, xue, xse, xme;

  ASSERT(display);
  memset(tbuf, 0, sizeof(tbuf));
  debug1("InitTermcap: looking for tgetent('%s')\n", D_termname);
  if (*D_termname == 0 || e_tgetent(tbuf, D_termname) != 1)
    {
#ifdef TERMINFO
      Msg(0, "Cannot find terminfo entry for '%s'.", D_termname);
#else
      Msg(0, "Cannot find termcap entry for '%s'.", D_termname);
#endif
      return -1;
    }
  debug1("got it:\n%s\n", tbuf);
#ifdef DEBUG
  if (extra_incap)
    debug1("Extra incap: %s\n", extra_incap);
  if (extra_outcap)
    debug1("Extra outcap: %s\n", extra_outcap);
#endif

  if ((D_tentry = (char *)malloc(TERMCAP_BUFSIZE + (extra_incap ? strlen(extra_incap) + 1 : 0))) == 0)
    {
      Msg(0, "%s", strnomem);
      return -1;
    }

  /*
   * loop through all needed capabilities, record their values in the display
   */
  tp = D_tentry;
  for (i = 0; i < T_N; i++)
    {
      switch(term[i].type)
	{
	case T_FLG:
	  D_tcs[i].flg = e_tgetflag(term[i].tcname);
	  break;
	case T_NUM:
	  D_tcs[i].num = e_tgetnum(term[i].tcname);
	  break;
	case T_STR:
	  D_tcs[i].str = e_tgetstr(term[i].tcname, &tp);
	  /* no empty strings, please */
	  if (D_tcs[i].str && *D_tcs[i].str == 0)
	    D_tcs[i].str = 0;
	  break;
	default:
	  Panic(0, "Illegal tc type in entry #%d", i);
	  /*NOTREACHED*/
	}
    }

  /*
   * Now a good deal of sanity checks on the retrieved capabilities.
   */
  if (D_HC)
    {
      Msg(0, "You can't run screen on a hardcopy terminal.");
      return -1;
    }
  if (D_OS)
    {
      Msg(0, "You can't run screen on a terminal that overstrikes.");
      return -1;
    }
  if (!D_CL)
    {
      Msg(0, "Clear screen capability required.");
      return -1;
    }
  if (!D_CM)
    {
      Msg(0, "Addressable cursor capability required.");
      return -1;
    }
  if ((s = getenv("COLUMNS")) && (i = atoi(s)) > 0)
    D_CO = i;
  if ((s = getenv("LINES")) && (i = atoi(s)) > 0)
    D_LI = i;
  if (wi)
    D_CO = wi;
  if (he)
    D_LI = he;
  if (D_CO <= 0)
    D_CO = 80;
  if (D_LI <= 0)
    D_LI = 24;

  if (D_CTF)
    {
      /* standard fixes for xterms etc */
      /* assume color for everything that looks ansi-compatible */
      if (!D_CAF && D_ME && (InStr(D_ME, "\033[m") || InStr(D_ME, "\033[0m")))
	{
#ifdef TERMINFO
	  D_CAF = "\033[3%p1%dm";
	  D_CAB = "\033[4%p1%dm";
#else
	  D_CAF = "\033[3%dm";
	  D_CAB = "\033[4%dm";
#endif
	}
      if (D_OP && InStr(D_OP, "\033[39;49m"))
        D_CAX = 1;
      if (D_OP && (InStr(D_OP, "\033[m") || InStr(D_OP, "\033[0m")))
        D_OP = 0;
      /* ISO2022 */
      if ((D_EA && InStr(D_EA, "\033(B")) || (D_AS && InStr(D_AS, "\033(0")))
	D_CG0 = 1;
      if (InStr(D_termname, "xterm") || InStr(D_termname, "rxvt") ||
	  (D_CKM && InStr(D_CKM, "\033[M")))
	D_CXT = 1;
      /* "be" seems to be standard for xterms... */
      if (D_CXT)
	D_BE = 1;
    }
  if (nwin_options.flowflag == nwin_undef.flowflag)
    nwin_default.flowflag = D_CNF ? FLOW_NOW * 0 : 
			    D_NX ? FLOW_NOW * 1 :
			    FLOW_AUTOFLAG;
  D_CLP |= (!D_AM || D_XV || D_XN);
  if (!D_BL)
    D_BL = "\007";
  if (!D_BC)
    {
      if (D_BS)
	D_BC = "\b";
      else
	D_BC = D_LE;
    }
  if (!D_CR)
    D_CR = "\r";
  if (!D_NL)
    D_NL = "\n";

  /*
   *  Set up attribute handling.
   *  This is rather complicated because termcap has different
   *  attribute groups.
   */

  if (D_UG > 0)
    D_US = D_UE = 0;
  if (D_SG > 0)
    D_SO = D_SE = 0;
  /* Unfortunately there is no 'mg' capability.
   * For now we think that mg > 0 if sg and ug > 0.
   */
  if (D_UG > 0 && D_SG > 0)
    D_MH = D_MD = D_MR = D_MB = D_ME = 0;

  xue = ATYP_U;
  xse = ATYP_S;
  xme = ATYP_M;

  if (D_SO && D_SE == 0)
    {
      Msg(0, "Warning: 'so' but no 'se' capability.");
      if (D_ME)
	xse = xme;
      else
	D_SO = 0;
    }
  if (D_US && D_UE == 0)
    {
      Msg(0, "Warning: 'us' but no 'ue' capability.");
      if (D_ME)
	xue = xme;
      else
	D_US = 0;
    }
  if ((D_MH || D_MD || D_MR || D_MB) && D_ME == 0)
    {
      Msg(0, "Warning: 'm?' but no 'me' capability.");
      D_MH = D_MD = D_MR = D_MB = 0;
    }
  /*
   * Does ME also reverse the effect of SO and/or US?  This is not
   * clearly specified by the termcap manual. Anyway, we should at
   * least look whether ME and SE/UE are equal:
   */
  if (D_UE && D_SE && strcmp(D_SE, D_UE) == 0)
    xse = xue;
  if (D_SE && D_ME && strcmp(D_ME, D_SE) == 0)
    xse = xme;
  if (D_UE && D_ME && strcmp(D_ME, D_UE) == 0)
    xue = xme;

  for (i = 0; i < NATTR; i++)
    {
      D_attrtab[i] = D_tcs[T_ATTR + i].str;
      D_attrtyp[i] = i == ATTR_SO ? xse : (i == ATTR_US ? xue : xme);
    }
  
  /* Set up missing entries (attributes are priority ordered) */
  s = 0;
  t = 0;
  for (i = 0; i < NATTR; i++)
    if ((s = D_attrtab[i]))
      {
	t = D_attrtyp[i];
	break;
      }
  for (i = 0; i < NATTR; i++)
    {
      if (D_attrtab[i] == 0)
	{
	  D_attrtab[i] = s;
	  D_attrtyp[i] = t;
	}
      else
        {
	  s = D_attrtab[i];
	  t = D_attrtyp[i];
        }
    }
  if (D_CAF || D_CAB || D_CSF || D_CSB)
    D_hascolor = 1;
  if (D_UT)
    D_BE = 1;	/* screen erased with background color */

  if (!D_DO)
    D_DO = D_NL;
  if (!D_SF)
    D_SF = D_NL;
  if (D_IN)
    D_IC = D_IM = 0;
  if (D_EI == 0)
    D_IM = 0;
  /* some strange termcap entries have IC == IM */
  if (D_IC && D_IM && strcmp(D_IC, D_IM) == 0)
    D_IC = 0;
  if (D_KE == 0)
    D_KS = 0;
  if (D_CVN == 0)
    D_CVR = 0;
  if (D_VE == 0)
    D_VI = D_VS = 0;
  if (D_CCE == 0)
    D_CCS = 0;

  if (D_CG0)
    {
      if (D_CS0 == 0)
#ifdef TERMINFO
        D_CS0 = "\033(%p1%c";
#else
        D_CS0 = "\033(%.";
#endif
      if (D_CE0 == 0)
        D_CE0 = "\033(B";
      D_AC = 0;
      D_EA = 0;
    }
  else if (D_AC || (D_AS && D_AE))	/* some kind of graphics */
    {
      D_CS0 = (D_AS && D_AE) ? D_AS : "";
      D_CE0 = (D_AS && D_AE) ? D_AE : "";
      D_CC0 = D_AC;
    }
  else
    {
      D_CS0 = D_CE0 = "";
      D_CC0 = 0;
      D_AC = "";	/* enable default string */
    }

  for (i = 0; i < 256; i++)
    D_c0_tab[i] = i;
  if (D_AC)
    {
      /* init with default string first */
      s = "l+m+k+j+u+t+v+w+q-x|n+o~s_p\"r#`+a:f'g#~o.v-^+<,>h#I#0#y<z>";
      for (i = strlen(s) & ~1; i >= 0; i -= 2)
	D_c0_tab[(int)(unsigned char)s[i]] = s[i + 1];
    }
  if (D_CC0)
    for (i = strlen(D_CC0) & ~1; i >= 0; i -= 2)
      D_c0_tab[(int)(unsigned char)D_CC0[i]] = D_CC0[i + 1];
  debug1("ISO2022 = %d\n", D_CG0);
  if (D_PF == 0)
    D_PO = 0;
  debug2("terminal size is %d, %d (says TERMCAP)\n", D_CO, D_LI);

  if (D_CXC)
    if (CreateTransTable(D_CXC))
      return -1;

  /* Termcap fields Z0 & Z1 contain width-changing sequences. */
  if (D_CZ1 == 0)
    D_CZ0 = 0;
  Z0width = 132;
  Z1width = 80;

  CheckScreenSize(0);

  if (D_TS == 0 || D_FS == 0 || D_DS == 0)
    D_HS = 0;
  if (D_HS)
    {
      debug("oy! we have a hardware status line, says termcap\n");
      if (D_WS < 0)
        D_WS = 0;
    }
  D_has_hstatus = hardstatusemu & ~HSTATUS_ALWAYS;
  if (D_HS && !(hardstatusemu & HSTATUS_ALWAYS))
    D_has_hstatus = HSTATUS_HS;

  if (D_CKJ)
    {
      int enc = FindEncoding(D_CKJ);
      if (enc != -1)
	D_encoding = enc;
    }
  if (!D_tcs[T_NAVIGATE].str && D_tcs[T_NAVIGATE + 1].str)
    D_tcs[T_NAVIGATE].str = D_tcs[T_NAVIGATE + 1].str;  /* kh = @1 */
  if (!D_tcs[T_NAVIGATE + 2].str && D_tcs[T_NAVIGATE + 3].str)
    D_tcs[T_NAVIGATE + 2].str = D_tcs[T_NAVIGATE + 3].str; /* kH = @7 */

  D_UPcost = CalcCost(D_UP);
  D_DOcost = CalcCost(D_DO);
  D_NLcost = CalcCost(D_NL);
  D_LEcost = CalcCost(D_BC);
  D_NDcost = CalcCost(D_ND);
  D_CRcost = CalcCost(D_CR);
  D_IMcost = CalcCost(D_IM);
  D_EIcost = CalcCost(D_EI);

  if (D_CAN)
    {
      debug("termcap has AN, setting autonuke\n");
      D_auto_nuke = 1;
    }
  if (D_COL > 0)
    {
      debug1("termcap has OL (%d), setting limit\n", D_COL);
      D_obufmax = D_COL;
      D_obuflenmax = D_obuflen - D_obufmax;
    }

  /* Some xterm entries set F0 and F10 to the same string. Nuke F0. */
  if (D_tcs[T_CAPS].str && D_tcs[T_CAPS + 10].str && !strcmp(D_tcs[T_CAPS].str, D_tcs[T_CAPS + 10].str))
    D_tcs[T_CAPS].str = 0;
  /* Some xterm entries set kD to ^?. Nuke it. */
  if (D_tcs[T_NAVIGATE_DELETE].str && !strcmp(D_tcs[T_NAVIGATE_DELETE].str, "\0177"))
    D_tcs[T_NAVIGATE_DELETE].str = 0;
  /* wyse52 entries have kcub1 == kb == ^H. Nuke... */
  if (D_tcs[T_CURSOR + 3].str && !strcmp(D_tcs[T_CURSOR + 3].str, "\008"))
    D_tcs[T_CURSOR + 3].str = 0;

  D_nseqs = 0;
  for (i = 0; i < T_OCAPS - T_CAPS; i++)
    remap(i, 1);
  for (i = 0; i < kmap_extn; i++)
    remap(i + (KMAP_KEYS+KMAP_AKEYS), 1);
  D_seqp = D_kmaps + 3;
  D_seql = 0;
  D_seqh = 0;

  D_tcinited = 1;
  MakeTermcap(0);
  CheckEscape();
  return 0;
}
Пример #30
0
EXPORT_C void CEikFixedPointEditor::SetMinMax(TInt aMin, TInt aMax)
	{
	iMin=aMin;
	iMax=aMax;
	__ASSERT_DEBUG(iMin<=iMax, Panic(EEikPanicInvalidBounds) );
	}