コード例 #1
0
ファイル: flash_stm32F1.c プロジェクト: MorS25/SnoreCopter
/**
  * @brief  Erases a specified FLASH page.
  * @param  Page_Address: The page address to be erased.
  * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
  *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  */
FLASH_Status FLASH_ErasePage(uint32 Page_Address)
{
	FLASH_Status status = FLASH_COMPLETE;
	/* Check the parameters */
	ASSERT(IS_FLASH_ADDRESS(Page_Address));
	/* Wait for last operation to be completed */
	status = FLASH_WaitForLastOperation(EraseTimeout);
  
	if(status == FLASH_COMPLETE)
	{
		/* if the previous operation is completed, proceed to erase the page */
		__set_bits(FLASH_CR, CR_PER_Set);
		__write(FLASH_AR, Page_Address);
		__set_bits(FLASH_CR, CR_STRT_Set);

		/* Wait for last operation to be completed */
		status = FLASH_WaitForLastOperation(EraseTimeout);
		if(status != FLASH_TIMEOUT)
		{
			/* if the erase operation is completed, disable the PER Bit */
			__clear_bits(FLASH_CR, ~CR_PER_Reset);
		}
		__write(FLASH_SR, (FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR));
	}
	/* Return the Erase Status */
	return status;
}
コード例 #2
0
ファイル: write.c プロジェクト: Ukusbobra/open-watcom-v2
_WCRTLINK int write( int handle, const void *buffer, unsigned len )
/*****************************************************************/
{
    unsigned    total = 0;
    unsigned    writeamt;
    int         rc;

    __handle_check( handle, -1 );

    // allow file to be truncated
    if( len == 0 )
        return( __write( handle, buffer, 0 ) );

    while( len > 0 ) {
        if( len > MAXBUFF ) {
            writeamt = MAXBUFF;
        } else {
            writeamt = len;
        }
        rc = __write( handle, buffer, writeamt );
        if( rc == -1 )
            return( rc );
        total += (unsigned)rc;
        if( rc != writeamt )
            return( total );

        len -= writeamt;
        buffer = ((const char *)buffer) + writeamt;
    }
    return( total );
}
コード例 #3
0
ファイル: videoDriver.c プロジェクト: SKOLZ/noxOS
void refreshKernelVideo(void) {
    int i;
    for (i = 0; i < VIDEO_ROWS; i++) {
        __write(1, video[i], VIDEO_COLUMNS);
    }
    setCursorPosition(0);
}
コード例 #4
0
ファイル: cp.c プロジェクト: cjphillips94/File_System
int _cp(char *src, char *dest)
{
  int fd, gd, ino, p_ino, dev = running->cwd->dev, temp;
  char src_path[INODE_NAME], dest_path[INODE_NAME], parent_path[INODE_NAME*2];
  MINODE *pip;

  strcpy(src_path, src);
  strcpy(dest_path, dest);
  strcpy(parent_path, dirname(dest));

  if (dest[0] == '/')
  {
    dev = root->dev;
  }
  temp = dev;

  ino = get_inode(dest_path, &temp, TRUE);
  if (ino < 0)                                    // Must first create the destination file
  {
    p_ino = get_inode(parent_path, &dev, FALSE);
    if (p_ino < 0)
    {
      return p_ino;
    }
    pip = iget(dev, p_ino);
    __creat(pip, basename(dest_path), REG_FILE);
    iput(pip);
  }

  fd = __open(src_path, 0); // open the source file for read
  if (fd < 0)
  {
    return fd;
  }
  gd = __open(dest_path, 1); // open the dest file for write
  if (gd < 0)
  {
    return gd;
  }

  int n = 0, counter = 0;
  char cp_buf[BLKSIZE];
  bzero(cp_buf, BLKSIZE);

  while ( (n = __read(fd, cp_buf, BLKSIZE)) > 0 ) // Read from the source file
  {
    if (n < 0)
      break;

    __write(gd, cp_buf, n);                       // Write to the destination file

    bzero(cp_buf, BLKSIZE);
    counter++;
  }

  __close(fd);
  __close(gd);

  return 0;
}
コード例 #5
0
ファイル: fputn.c プロジェクト: Mephistophil/linked_list
size_t __fputnt( const _TCHAR *ptr, size_t n, register FILE *fp /* , int eos_flag */)
{
    int ret;


#if !defined(_UNICODE)
    if( fp->flags & _F_LBUF )       /* if it's line buffered or widechar, */
#endif
    {                               /* handle it in the traditional way */
        int len;
        _TCHAR *p;

        for (len = n, p = (_TCHAR *)ptr; len != 0; len--, p++ )
        {
            if( _lputtc( *p, fp ) == _TEOF )
                return( 0 );
        }

        return( n );
    }
#if !defined (_UNICODE)
    else if (fp->bsize && n <= (unsigned)fp->bsize)   /* buffer big enough? */
    {
        if( fp->level + (int)n >= 0 )  /* must we flush it to make room? */
        {
            if( fp->level == 0 )
            {
                fp->level = -1 - fp->bsize;
            }
            else
            {
                if( fflush( fp ) )
                    return( 0 );
            }
        }

        /* stuff it into the file buffer all at once! */
        memcpy( fp->curp, ptr, n );
        fp->level += n;
        fp->curp += n;

        return( n );
    }
    else            /* it is unbuffered or buffer is too small */
    {
        if (fp->bsize && fp->level)     /* something in the buffer? */
        {
            if( fflush( fp ) )
                return( 0 );
        }

        /* write it all at once! */
        ret = __write( fp->fd, (void *)ptr, n );
        if( (ret == -1) || ((unsigned)ret < n ))
            return( 0 );
        else
            return( n );
    }
#endif /* _UNICODE */
}
コード例 #6
0
ファイル: stdio.c プロジェクト: pradoAgustin/TP-arqui
/***************************************************************
*  putc (si)
****************************************************************/
int putc(char c, FILE * stdout){
	int i=0 ;
	if(c=='\b')
	{	
		backspace();
		return;
	}
	if(c=='\n')
	{	
		enter();
		return;
	}
	if(c=='\t')
	{
		tab();
		return;
	}
	update_cursor();
	if(stdout==(FILE *)1 && c!=0){
		__write(1,c,1);
		_inc_b();
	}	
	
cursor+=i;
if(cursor>(160*25)){
	k_scroll();
	cursor=77*2*25-8;
}
}
コード例 #7
0
ファイル: flash_stm32F1.c プロジェクト: MorS25/SnoreCopter
/**
  * @brief  Programs a half word at a specified address.
  * @param  Address: specifies the address to be programmed.
  * @param  Data: specifies the data to be programmed.
  * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. 
  */
FLASH_Status FLASH_ProgramHalfWord(uint32 Address, uint16 Data)
{
	FLASH_Status status = FLASH_BAD_ADDRESS;

	if (IS_FLASH_ADDRESS(Address))
	{
		/* Wait for last operation to be completed */
		status = FLASH_WaitForLastOperation(ProgramTimeout);
		if(status == FLASH_COMPLETE)
		{
			/* if the previous operation is completed, proceed to program the new data */
			__set_bits(FLASH_CR, CR_PG_Set);
			*(__io uint16*)Address = Data;
			/* Wait for last operation to be completed */
			status = FLASH_WaitForLastOperation(ProgramTimeout);
			if(status != FLASH_TIMEOUT)
			{
				/* if the program operation is completed, disable the PG Bit */
				__clear_bits(FLASH_CR, ~CR_PG_Reset);
			}
			__write(FLASH_SR, (FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR));
		}
	}
	return status;
}
コード例 #8
0
ファイル: pwrite.c プロジェクト: ArmstrongJ/MiNTLib
ssize_t
__pwrite (int fd, const void *buf, size_t nbyte, off_t offset)
{
  /* Since we must not change the file pointer preserve the value so that
     we can restore it later.  */
  int save_errno;
  ssize_t result;
  off_t old_offset = __lseek (fd, 0, SEEK_CUR);
  if (old_offset == (off_t) -1)
    return -1;

  /* Set to wanted position.  */
  if (__lseek (fd, offset, SEEK_SET) == (off_t) -1)
    return -1;

  /* Write out the data.  */
  result = __write (fd, buf, nbyte);

  /* Now we have to restore the position.  If this fails we have to
     return this as an error.  But if the writing also failed we
     return this error.  */
  save_errno = errno;
  if (__lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
    {
      if (result == -1)
	__set_errno (save_errno);
      return -1;
    }
  __set_errno (save_errno);

  return result;
}
コード例 #9
0
ファイル: flushout.c プロジェクト: Mephistophil/linked_list
/*---------------------------------------------------------------------*

Name            _flushout - writes all output buffers

Usage           int _flushout(void);

Prototype in    stdio.h

Description     Writes all buffers associated with open output streams
                to their respective files.

Return value    the number of open output streams

*---------------------------------------------------------------------*/
int _RTLENTRY _EXPFUNC _flushout(void)
{
    register FILE   *fp;
    register int    Nb;
    int             Cpt;
    int             count;

    _lock_all_streams();

    for (Cpt = 0, Nb = _nfile, fp = _streams; Nb--; fp++)
        if( fp->level < 0 )                 /* output data waiting in buffer */
            {
            count = fp->bsize + 1 + fp->level;
            fp->level -= count;

            if( (__write( fp->fd, (fp->curp = fp->buffer), count ) != count) &&
                ((fp->flags & _F_TERM) == 0) )
                {
                fp->flags |= _F_ERR;
                }
            Cpt++;
            }

    _unlock_all_streams();
    return(Cpt);
}
コード例 #10
0
int global_cached_io::handle_pending_requests()
{
	int tot = 0;
	std::vector<thread_safe_page *> dirty_pages;
	while (!pending_requests.is_empty()) {
		page_req_pair reqs[MAX_FETCH_REQS];
		int num = pending_requests.fetch(reqs, MAX_FETCH_REQS);
		for (int i = 0; i < num; i++) {
			// It may be the head of a request list. All requests
			// in the list should point to the same page.
			original_io_request *req = reqs[i].second;
			thread_safe_page *p = reqs[i].first;
			assert(!p->is_old_dirty());
			/**
			 * Right now all pending requests are writes.
			 * All writes are single-buf requests.
			 */
			assert(req->get_next_req_on_page(p) == NULL);
			assert(req->get_io() == this);
			if (req->get_access_method() == WRITE)
				__write(req, p, dirty_pages);
			else
				__read(req, p);
		}
		tot += num;
	}
	// It's not very likely we can get dirty pages here because this is
	// the place where we just finish writing old dirty pages to the disk.
	// The only possible reason is that we happen to overwrite the entire
	// page.
	get_global_cache()->mark_dirty_pages(dirty_pages.data(),
			dirty_pages.size(), underlying);
	return tot;
}
コード例 #11
0
ファイル: assfail.c プロジェクト: jasonbking/illumos-gate
void
__assfail(const char *assertion, const char *filename, int line_num)
{
	char buf[800];	/* no assert() message in the library is this long */
	ulwp_t *self;
	lwpid_t lwpid;

	/* avoid recursion deadlock */
	if ((self = __curthread()) != NULL) {
		if (assert_thread == self)
			_exit(127);
		enter_critical(self);
		(void) _lwp_mutex_lock(&assert_lock);
		assert_thread = self;
		lwpid = self->ul_lwpid;
	} else {
		self = NULL;
		(void) _lwp_mutex_lock(&assert_lock);
		lwpid = _lwp_self();
	}

	/*
	 * This is a hack, but since the Abort function isn't exported
	 * to outside consumers, libzpool's vpanic() function calls
	 * assfail() with a filename set to NULL. In that case, it'd be
	 * best not to print "assertion failed" since it was a panic and
	 * not an assertion failure.
	 */
	if (filename == NULL) {
		(void) strcpy(buf, "failure for thread ");
	} else {
		(void) strcpy(buf, "assertion failed for thread ");
	}

	ultos((uint64_t)(uintptr_t)self, 16, buf + strlen(buf));
	(void) strcat(buf, ", thread-id ");
	ultos((uint64_t)lwpid, 10, buf + strlen(buf));
	(void) strcat(buf, ": ");
	(void) strcat(buf, assertion);

	if (filename != NULL) {
		(void) strcat(buf, ", file ");
		(void) strcat(buf, filename);
		(void) strcat(buf, ", line ");
		ultos((uint64_t)line_num, 10, buf + strlen(buf));
	}

	(void) strcat(buf, "\n");
	(void) __write(2, buf, strlen(buf));
	/*
	 * We could replace the call to Abort() with the following code
	 * if we want just to issue a warning message and not die.
	 *	assert_thread = NULL;
	 *	_lwp_mutex_unlock(&assert_lock);
	 *	if (self != NULL)
	 *		exit_critical(self);
	 */
	Abort(buf);
}
コード例 #12
0
ファイル: spu.c プロジェクト: dhobsong/omxil-sh
static void
_write (struct spu2_dsp *_this, u32 * addr, u32 * data, u32 size)
{
	int i;

	for (i = 0; i < size; i++)
		__write (_this, (u32) addr + (u32) (i * 4), data[i]);
}
コード例 #13
0
ファイル: svc_simple.c プロジェクト: OSLL/elfperf
static void
universal (struct svc_req *rqstp, SVCXPRT *transp_l)
{
  int prog, proc;
  char *outdata;
  char xdrbuf[UDPMSGSIZE];
  struct proglst_ *pl;
  char *buf = NULL;

  /*
   * enforce "procnum 0 is echo" convention
   */
  if (rqstp->rq_proc == NULLPROC)
    {
      if (INTUSE(svc_sendreply) (transp_l, (xdrproc_t)INTUSE(xdr_void),
				 (char *) NULL) == FALSE)
	{
	  __write (STDERR_FILENO, "xxx\n", 4);
	  exit (1);
	}
      return;
    }
  prog = rqstp->rq_prog;
  proc = rqstp->rq_proc;
  for (pl = proglst; pl != NULL; pl = pl->p_nxt)
    if (pl->p_prognum == prog && pl->p_procnum == proc)
      {
	/* decode arguments into a CLEAN buffer */
	__bzero (xdrbuf, sizeof (xdrbuf));	/* required ! */
	if (!svc_getargs (transp_l, pl->p_inproc, xdrbuf))
	  {
	    INTUSE(svcerr_decode) (transp_l);
	    return;
	  }
	outdata = (*(pl->p_progname)) (xdrbuf);
	if (outdata == NULL && pl->p_outproc != (xdrproc_t)INTUSE(xdr_void))
	  /* there was an error */
	  return;
	if (!INTUSE(svc_sendreply) (transp_l, pl->p_outproc, outdata))
	  {
	    if (__asprintf (&buf, _("trouble replying to prog %d\n"),
			    pl->p_prognum) < 0)
	      buf = NULL;
	    goto err_out2;
	  }
	/* free the decoded arguments */
	(void) svc_freeargs (transp_l, pl->p_inproc, xdrbuf);
	return;
      }
  if (__asprintf (&buf, _("never registered prog %d\n"), prog) < 0)
    buf = NULL;
 err_out2:
  if (buf == NULL)
    exit (1);
  __fxprintf (NULL, "%s", buf);
  free (buf);
  exit (1);
}
コード例 #14
0
ファイル: io_count.c プロジェクト: GSathish/casamia-datastore
ssize_t write(int fd, const void * buf, size_t count)
{
	do_setup();
	if(!isatty(fd))
	{
		io_stats.write_total += count;
		io_stats.write_calls++;
	}
	return __write(fd, buf, count);
}
コード例 #15
0
ファイル: stdio.c プロジェクト: joseignaciosg/SO--TP3-2011
void
putc(char c) {
	void * p;
	int i;
	p = &c;
	if (c == '\n')
		enter();
	else if(c == '\t')
	{
		c = ' ';
		p = &c;
		for(i = 0; i < 8; i++)
			__write(WRITE, STDOUT, p, 1);
	}
	else
		__write(WRITE, STDOUT, p, 1);
	moveCursor();
	return;
}
コード例 #16
0
ファイル: coverity-model.c プロジェクト: CasonChan/qemu
bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
                      int len, bool is_write)
{
    bool result;

    // TODO: investigate impact of treating reads as producing
    // tainted data, with __coverity_tainted_data_argument__(buf).
    if (is_write) __write(buf, len); else __read(buf, len);

    return result;
}
コード例 #17
0
ファイル: functions.c プロジェクト: hreinecke/s390-tools
/**
 * iucvtty_write_msg() - Write/Send IUCV message
 * @fd:		File descriptor
 * @msg:	Pointer to IUCV message
 */
int iucvtty_write_msg(int fd, struct iucvtty_msg *msg)
{
	msg->version = MSG_VERSION;

	if (__write(fd, msg, msg_size(msg)) <= 0)
		return -1;

#ifdef __DEBUG__
	__dump_msg(fd, msg, 'S');
#endif
	return 0;
}
コード例 #18
0
ファイル: writev.c プロジェクト: kstraube/rampgold_fixed
/* Write data pointed by the buffers described by VECTOR, which
   is a vector of COUNT 'struct iovec's, to file descriptor FD.
   The data is written in the order specified.
   Operates just like 'write' (see <unistd.h>) except that the data
   are taken from VECTOR instead of a contiguous buffer.  */
ssize_t
__libc_writev (int fd, const struct iovec *vector, int count)
{
  /* Find the total number of bytes to be written.  */
  size_t bytes = 0;
  for (int i = 0; i < count; ++i)
    {
      /* Check for ssize_t overflow.  */
      if (SSIZE_MAX - bytes < vector[i].iov_len)
	{
	  __set_errno (EINVAL);
	  return -1;
	}
      bytes += vector[i].iov_len;
    }

  /* Allocate a temporary buffer to hold the data.  We should normally
     use alloca since it's faster and does not require synchronization
     with other threads.  But we cannot if the amount of memory
     required is too large.  */
  char *buffer;
  char *malloced_buffer = NULL;
  if (__libc_use_alloca (bytes))
    buffer = (char *) __alloca (bytes);
  else
    {
      malloced_buffer = buffer = (char *) malloc (bytes);
      if (buffer == NULL)
	/* XXX I don't know whether it is acceptable to try writing
	   the data in chunks.  Probably not so we just fail here.  */
	return -1;
    }

  /* Copy the data into BUFFER.  */
  size_t to_copy = bytes;
  char *bp = buffer;
  for (int i = 0; i < count; ++i)
    {
      size_t copy = MIN (vector[i].iov_len, to_copy);

      bp = __mempcpy ((void *) bp, (void *) vector[i].iov_base, copy);

      to_copy -= copy;
      if (to_copy == 0)
	break;
    }

  ssize_t bytes_written = __write (fd, buffer, bytes);

  free(malloced_buffer);

  return bytes_written;
}
コード例 #19
0
ファイル: linux-atomic-64bit.c プロジェクト: AlexMioMio/gcc
/* Check that the kernel has a new enough version at load.  */
static void __check_for_sync8_kernelhelper (void)
{
  if (__kernel_helper_version < 5)
    {
      const char err[] = "A newer kernel is required to run this binary. "
				"(__kernel_cmpxchg64 helper)\n";
      /* At this point we need a way to crash with some information
	 for the user - I'm not sure I can rely on much else being
	 available at this point, so do the same as generic-morestack.c
	 write () and abort ().  */
      __write (2 /* stderr.  */, err, sizeof (err));
      abort ();
    }
};
コード例 #20
0
/*
 * writes data to the tcp connection.
 * Any error is fatal and the connection is closed.
 */
static int
writetcp (char *xprtptr, char * buf, int len)
{
  SVCXPRT *xprt = (SVCXPRT *)xprtptr;
  int i, cnt;

  for (cnt = len; cnt > 0; cnt -= i, buf += i)
    {
      if ((i = __write (xprt->xp_sock, buf, cnt)) < 0)
	{
	  ((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
	  return -1;
	}
    }
  return len;
}
コード例 #21
0
ファイル: coordinator.cpp プロジェクト: semajrolyat/tas
//-----------------------------------------------------------------------------
void timer_sighandler( int signum, siginfo_t *si, void *data ) {

  notification_t note;
  static int fd = FD_TIMER_TO_COORDINATOR_WRITE_CHANNEL;
  std::string err;

  note.ts = generate_timestamp();
  note.source = notification_t::TIMER;
  ssize_t bytes_written = 0;

  if( __write( fd, &note, sizeof(notification_t), bytes_written ) != OS_ERROR_NONE ) {
    err = "(coordinator.cpp) timer_sighandler(...) failed making system call write(...)";
    //error_log.write( error_string_bad_write( err, errno ) );
    // TODO : determine if there is a need to recover
  }
}
コード例 #22
0
ファイル: clnt_tcp.c プロジェクト: JamesLinus/glibc-mips
static int
writetcp (char *ctptr, char *buf, int len)
{
  int i, cnt;
  struct ct_data *ct = (struct ct_data*)ctptr;

  for (cnt = len; cnt > 0; cnt -= i, buf += i)
    {
      if ((i = __write (ct->ct_sock, buf, cnt)) == -1)
	{
	  ct->ct_error.re_errno = errno;
	  ct->ct_error.re_status = RPC_CANTSEND;
	  return -1;
	}
    }
  return len;
}
コード例 #23
0
ファイル: fflush.c プロジェクト: Mephistophil/linked_list
int _RTLENTRY _EXPFUNC  fflush (FILE *fp)
{
    register count;
    int rc;

    if( fp == NULL )
    {
        _flushout();
        return (0);
    }

    if( fp->token != (unsigned char)fp )
        return( EOF );      /* validity check */

    _lock_stream(fp);

    if( fp->level >= 0 )                    /* no output data in buffer */
    {
        if( fp->flags & _F_LBUF ||
            fp->curp == (unsigned char*)&fp->hold )
        {
            fp->level = 0;                  /* ensure no unget char */
            if( fp->curp == (unsigned char*)&fp->hold )
            fp->curp = fp->buffer;
        }

        RETURN( 0 );
    }

    count = fp->bsize + 1 + fp->level;
    fp->level -= count;

    if( (__write( fp->fd, (fp->curp = fp->buffer), count ) != count) &&
        ((fp->flags & _F_TERM) == 0) )
    {
        fp->flags |= _F_ERR;
        RETURN( EOF );
    }

    rc = 0;

exit:
    _unlock_stream(fp);
    return (rc);
}
コード例 #24
0
ファイル: test_client.cpp プロジェクト: semajrolyat/tas
//-----------------------------------------------------------------------------
void timer_sighandler( int signum, siginfo_t *si, void *data ) {
  //std::string err, eno;

  // grab a timestamp immediately
  timer_note.ts = generate_timestamp();

  // increment accounting
  actual_timer_events++;

  ssize_t bytes_written;
  // write the timer notification to the pipe
  if( __write( timer_write_fd, &timer_note, sizeof(notification_t), bytes_written ) != OS_ERROR_NONE ) {
    // TODO: restructure to reduce complexity here.
/*
    if( errno == EPIPE )
      eno = " errno: EPIPE";
    else if( errno == EAGAIN || errno == EWOULDBLOCK )
      eno = " errno: EWOULDBLOCK";
    else if( errno == EBADF )
      eno = " errno: EBADF";
    else if( errno == EDESTADDRREQ )
      eno = " errno: EDESTADDRREQ";
    else if( errno == EDQUOT )
      eno = " errno: EDQUOT";
    else if( errno == EFAULT )
      eno = " errno: EFAULT";
    else if( errno == EFBIG )
      eno = " errno: EFBIG";
    else if( errno == EINTR )
      eno = " errno: EINTR";
    else if( errno == EINVAL )
      eno = " errno: EINVAL";
    else if( errno == EIO )
      eno = " errno: EIO";
    else if( errno == ENOSPC )
      eno = " errno: ENOSPC";

    err = "(coordinator.cpp) timer_sighandler(...) failed making system call write(...)" + eno;
    //sprintf( spstr, "(coordinator.cpp) timer_sighandler(...) failed making system call write(...) %s\n", eno );
    printf( "%s\n", err );
    // TODO : determine if there is a need to recover
*/
  }
}
コード例 #25
0
ファイル: assfail.c プロジェクト: jasonbking/illumos-gate
/*
 * Report a thread usage error.
 * Not called if _THREAD_ERROR_DETECTION=0.
 * Writes message and continues execution if _THREAD_ERROR_DETECTION=1.
 * Writes message and dumps core if _THREAD_ERROR_DETECTION=2.
 */
void
thread_error(const char *msg)
{
	char buf[800];
	uberdata_t *udp;
	ulwp_t *self;
	lwpid_t lwpid;

	/* avoid recursion deadlock */
	if ((self = __curthread()) != NULL) {
		if (assert_thread == self)
			_exit(127);
		enter_critical(self);
		(void) _lwp_mutex_lock(&assert_lock);
		assert_thread = self;
		lwpid = self->ul_lwpid;
		udp = self->ul_uberdata;
	} else {
		self = NULL;
		(void) _lwp_mutex_lock(&assert_lock);
		lwpid = _lwp_self();
		udp = &__uberdata;
	}

	(void) strcpy(buf, "\n*** _THREAD_ERROR_DETECTION: "
	    "thread usage error detected ***\n*** ");
	(void) strcat(buf, msg);

	(void) strcat(buf, "\n*** calling thread is ");
	ultos((uint64_t)(uintptr_t)self, 16, buf + strlen(buf));
	(void) strcat(buf, " thread-id ");
	ultos((uint64_t)lwpid, 10, buf + strlen(buf));
	(void) strcat(buf, "\n\n");
	(void) __write(2, buf, strlen(buf));
	if (udp->uberflags.uf_thread_error_detection >= 2)
		Abort(buf);
	assert_thread = NULL;
	(void) _lwp_mutex_unlock(&assert_lock);
	if (self != NULL)
		exit_critical(self);
}
コード例 #26
0
ファイル: client_process.cpp プロジェクト: semajrolyat/tas
//-----------------------------------------------------------------------------
void write( notification_t& note ) {
  char eno[16];

  // update the timestamp on the note
  note.ts = generate_timestamp();
  ssize_t bytes_written;

  os_error_e result;
  result = __write( write_fd, &note, sizeof(notification_t), bytes_written );
  if( result != OS_ERROR_NONE ) {
///*
    if( result == OS_ERROR_PIPE )
      sprintf( eno, "EPIPE" );
    else if( result == OS_ERROR_AGAIN )
      sprintf( eno, "EWOULDBLOCK" );
    else if( result == OS_ERROR_BADF )
      sprintf( eno, "EBADF" );
    else if( result == OS_ERROR_DESTADDRREQ )
      sprintf( eno, "EDESTADDRREQ" );
    else if( result == OS_ERROR_DQUOT )
      sprintf( eno, "EDQUOT" );
    else if( result == OS_ERROR_FAULT )
      sprintf( eno, "EFAULT" );
    else if( result == OS_ERROR_FBIG )
      sprintf( eno, "EFBIG" );
    else if( result == OS_ERROR_INTR )
      sprintf( eno, "EINTR" );
    else if( result == OS_ERROR_INVAL )
      sprintf( eno, "EINVAL" );
    else if( result == OS_ERROR_IO )
      sprintf( eno, "EIO" );
    else if( result == OS_ERROR_NOSPC )
      sprintf( eno, "ENOSPC" );
    printf( "ERROR: (%s) failed making system call write(...) errno[%s]\n", mythread->name, eno );
//*/
  }
}
コード例 #27
0
int _FARFUNC fflush( register FILE *fp )
  {
  register count;

  if( !fp )
    {
    flushall();
    }
  else
    {
    if( fp->token != (short)fp )  return( EOF );      /* validity check */

    if( fp->level >= 0 )                    /* no output data in buffer */
      {
      if( fp->flags & _F_LBUF || fp->curp == &fp->hold )
        {
        fp->level = 0;                          /* ensure no unget char */
        if( fp->curp == &fp->hold )  fp->curp = fp->buffer;
        }

      return( 0 );
      }

    count = fp->bsize + 1 + fp->level;
    fp->level -= count;

    if( (__write( fp->fd, (fp->curp = fp->buffer), count ) != count) &&
      ((fp->flags & _F_TERM) == 0) )
      {
      fp->flags |= _F_ERR;
      return( EOF );
      }
    }

  return( 0 );
  }
コード例 #28
0
ファイル: debug_printf.c プロジェクト: Cheng-SG/BubbleCode
int _debug_printf_flush()
{
	uint8_t len, written;

	len = debug_buf_read_index <= debug_buf_write_index
			? debug_buf_write_index - debug_buf_read_index
			: DEBUG_OUTPUT_BUFFER_SIZE - debug_buf_read_index;

	if(!len)
		return 0;

	// The following if() disables semihosted writes when there is no hosted debugger
	// Otherwise, the target will halt when the semihost __write is called
	if(ISDEBUGACTIVE())
	    written = __write(0, &debug_write_buf[debug_buf_read_index], len);
	else
            written = 0;

	debug_buf_read_index = (debug_buf_read_index + written) % DEBUG_OUTPUT_BUFFER_SIZE;

	if(written != len)
		return written;
	return _debug_printf_flush() + written;
}
コード例 #29
0
ファイル: assfail.c プロジェクト: jasonbking/illumos-gate
/*
 * Write a panic message w/o grabbing any locks other than assert_lock.
 * We have no idea what locks are held at this point.
 */
void
common_panic(const char *head, const char *why)
{
	char msg[400];	/* no panic() message in the library is this long */
	ulwp_t *self;
	size_t len1, len2;

	if ((self = __curthread()) != NULL)
		enter_critical(self);
	(void) _lwp_mutex_lock(&assert_lock);

	(void) memset(msg, 0, sizeof (msg));
	(void) strcpy(msg, head);
	len1 = strlen(msg);
	len2 = strlen(why);
	if (len1 + len2 >= sizeof (msg))
		len2 = sizeof (msg) - len1 - 1;
	(void) strncat(msg, why, len2);
	len1 = strlen(msg);
	if (msg[len1 - 1] != '\n')
		msg[len1++] = '\n';
	(void) __write(2, msg, len1);
	Abort(msg);
}
コード例 #30
0
ファイル: stdio.c プロジェクト: joseignaciosg/SO--TP3-2011
void
clearc(char c) {
	void *p = &c;
	__write(ERASE, STDOUT, p, 1);
	return;
}