static unit_version_t *
hosting_plugin_load (const char *plugin_dll_name, const char *plugin_load_path)
{
  char *filename, *funname;
  const char *dot;
  hosting_version_t *hver;
  int inx;
  size_t file_name_max_len = strlen (plugin_load_path) + 1 + strlen (plugin_dll_name) + 1;
  size_t funname_max_len;

  filename = (char *) dk_alloc (strlen (plugin_load_path) + 1 + strlen (plugin_dll_name) + 1);
  snprintf (filename, file_name_max_len, "%s/%s", plugin_load_path, plugin_dll_name);
  funname_max_len = strlen (plugin_dll_name) + 6 /* == strlen ("_check") */ + 1;

  filename = (char *) dk_alloc (file_name_max_len);
  snprintf (filename, file_name_max_len, "%s/%s", plugin_load_path, plugin_dll_name);
  funname = (char *) dk_alloc (funname_max_len);
  dot = strchr (plugin_dll_name, '.');
  if (!dot)
    dot = plugin_dll_name + strlen (plugin_dll_name);
  strncpy (funname, plugin_dll_name, dot - plugin_dll_name);
  funname[dot - plugin_dll_name] = 0;
  strncat_size_ck (funname, "_check", funname_max_len - strlen (funname) - 1, funname_max_len);
  hver = hosting_load_and_check_plugin (filename, funname, &dock_hosting_version, NULL);

  for (inx = 0; hver->hv_extensions && hver->hv_extensions[inx]; inx++)
    {
      caddr_t ext = box_dv_short_string (hver->hv_extensions[inx]);
      id_hash_set (ext_hash, (caddr_t) &ext, (caddr_t) &hver);
    }

  return &(hver->hv_pversion);
}
static thread_t *
thread_alloc ()
{
  thread_t *thr;

  thr = (thread_t *) dk_alloc (sizeof (thread_t));
  memset (thr, 0, sizeof (thread_t));
  thr->thr_status = RUNNABLE;
  thr->thr_handle = dk_alloc (sizeof (pthread_t));
  thr->thr_cv = _alloc_cv ();
  thr->thr_sem = semaphore_allocate (0);
  thr->thr_schedule_sem = semaphore_allocate (0);

  return thr;
}
void *
dk_alloc_zero (size_t c)
{
  void * thing = dk_alloc (c);
  memset (thing, 0, c);
  return thing;
}
Exemple #4
0
void *
CTransactResourceAsync::operator
new (size_t sz)
{
    MTS_TRACE (("TRA::operator new...\n"));
    return dk_alloc (sz);
};
Exemple #5
0
int
mts_trx_enlist (lock_trx_t * lt, caddr_t tr_cookie, unsigned long len)
{
  if (!local_rm)
    {
      return 1;
    }
  DOUBLE_LOCK (trx_import, enlist);
  if (!local_rm->rm)
    {
      RELEASE_OBJECT (local_rm);
      return 0;
    }
  try
  {
    HRESULT hr =
	DtcGetTransactionManager (0, 0, __uuidof (ITransactionImport),
	0, 0, 0, (void **) &local_rm->trx_import);
    MTS_THROW_ASSERT (hr, "Get Transaction Import");
  }
  catch (const mts_error & err)
  {
    err.dump ();
    RELEASE_OBJECT (local_rm);
    return err.get_errcode ();
  }
  RELEASE_OBJECT (local_rm);
enlist:
  try
  {
    auto_interface < ITransaction > itrx;
    tp_data_t *tpd;
    HRESULT hr = local_rm->trx_import->Import (len,
	(BYTE *) tr_cookie,
	(IID *) & __uuidof (ITransaction),
	(void **) &itrx.get ());
    MTS_THROW_ASSERT (hr, "Import transaction");

    hr = mts_trx_enlist_loc (lt->lt_client, itrx.get ());
    MTS_THROW_ASSERT (hr, "Enlist local transaction");
    tpd = (tp_data_t *) dk_alloc (sizeof (tp_data_t));
    memset (tpd, 0, sizeof (tp_data_t));
    tpd->cli_tp_enlisted = CONNECTION_PREPARED;
    tpd->cli_tp_trx = itrx.release ();
    tpd->cli_tp_sem2 = semaphore_allocate (0);
    lt->lt_client->cli_tp_data = tpd;
    lt->lt_2pc._2pc_type = tpd->cli_trx_type = TP_MTS_TYPE;
#ifdef MSDTC_DEBUG
    lt->lt_in_mts = 1;
#endif
  }
  catch (const mts_error & err)
  {
    err.dump ();
    return err.get_errcode ();
  }
  return 0;
};
thread_t *
thread_allocate ()
{
  thread_t *thr;
  thr = (thread_t *) dk_alloc (sizeof (thread_t));
  memset (thr, 0, sizeof (thread_t));
  thr->thr_sem = semaphore_allocate (0);
  thr->thr_schedule_sem = semaphore_allocate (0);

  return thr;
}
Exemple #7
0
/* 
 * Allocate core for ramdisk(s)
 */
size_t
raminit()
{
	if (ram_size) {
		if (ram_base = malloc(coremap, ram_size*btoc(NBPG))) {
#ifdef UCB_METER
			dk_alloc(&ram_dkn, 1, "ram", 0L);
#endif
			return(ram_size*btoc(NBPG));
		}
		printf("ram: nospace\n");
	}
	return(0);
}
Exemple #8
0
caddr_t
mts_get_rmcookie ()
{
  if (!local_rm)
    {
      return 0;
    }

  DOUBLE_LOCK (rmcookie, alloc_ret);

  try
  {
    auto_interface < ITransactionImportWhereabouts > import_abouts;
    HRESULT hr = DtcGetTransactionManager (0,
	0,
	__uuidof (ITransactionImportWhereabouts),
	0,
	0,
	0,
	(void **) &import_abouts.get ());
    MTS_THROW_ASSERT (hr, "Get ITransactionImportWhereabouts");

    hr = import_abouts->GetWhereaboutsSize (&local_rm->rmcookie_len);
    MTS_THROW_ASSERT (hr, "GetTransactionImportWhereaboutsLen");

    DWORD used;
    auto_dkptr < BYTE >
	whereabouts_aptr ((BYTE *) dk_alloc (sizeof (BYTE) *
	    local_rm->rmcookie_len));
    hr = import_abouts->GetWhereabouts (local_rm->rmcookie_len,
	whereabouts_aptr.get (), &used);

    local_rm->rmcookie = whereabouts_aptr.release ();
  }
  catch (const mts_error & err)
  {
    RELEASE_OBJECT (local_rm);
    err.dump ();
    return 0;
  }
  RELEASE_OBJECT (local_rm);

alloc_ret:
  caddr_t cookie = (caddr_t) dk_alloc_box (local_rm->rmcookie_len, DV_BIN);
  memcpy (cookie, local_rm->rmcookie, local_rm->rmcookie_len);

  return cookie;
};
Exemple #9
0
void *
export_mts_trx_allocate ()
{
  static tp_trx_vtbl_t mts_vtbl = {
    mts_ms_sql_enlist,
    mts_trx_commit,
    mts_trx_commit_stage_2,
    mts_trx_exclude,
    mts_trx_dealloc
  };
  NEW_VARZ (tp_dtrx_t, dtrx);
  dtrx->vtbl = &mts_vtbl;
  dtrx->dtrx_info = (caddr_t) dk_alloc (sizeof (mts_t));
  memset (dtrx->dtrx_info, 0, sizeof (mts_t));

  return (void *) dtrx;
};
Exemple #10
0
void rdisk_init()
{
    int i;

    //printf("Prepartition Schema: %s\n",prepartition_schema);

#ifdef UCB_METER
    dk_alloc(&rddk, NRDSK, "rd");
#endif

    for (i=0; i<NRDSK; i++) {
        disks[i].pre_init(disks[i].unit);
        if (disks[i].settings & RD_PREPART) {
            //TODO
        }
    }
}
Exemple #11
0
mts_RM_t *
init_RM ()
{
  MTS_TRACE (("init_RM\n"));
  mts_RM_t *rm = (mts_RM_t *) dk_alloc (sizeof (mts_RM_t));
  memset (rm, 0, sizeof (mts_RM_t));

  try
  {
    auto_interface < IResourceManagerFactory > rm_factory;
    HRESULT hr =
	DtcGetTransactionManager (0, 0, __uuidof (IResourceManagerFactory),
	0, 0, 0, (void **) &rm_factory.get ());
    MTS_THROW_ASSERT (hr, "Get RM Factory");

    int guid = open ("guid.bin", O_RDONLY | O_BINARY);
    if (-1 == guid)
      {
/*	log_info("Generating RM GUID..."); */
	guid = open ("guid.bin", O_CREAT | O_WRONLY | O_BINARY);
	UuidCreate (&VirtRMGUID);
	write (guid, &VirtRMGUID, sizeof (VirtRMGUID));
      }
    else
      read (guid, &VirtRMGUID, sizeof (VirtRMGUID));

    hr = rm_factory->Create (&VirtRMGUID, "Virtuoso Resource Manager",
	new CResMgrSink, &(rm->rm));
    MTS_THROW_ASSERT (hr, "Create RM");

    hr = DtcGetTransactionManager (0, 0, __uuidof (ITransactionDispenser),
	0, 0, 0, (void **) &(rm->trx_dispenser));
    MTS_THROW_ASSERT (hr, "Get Transaction Dispenser");
  }
  catch (const mts_error & err)
  {
    err.dump ();
    vd_use_mts = 0;
    /* log_info ("MS DTC could not be found, call reconnect"); */
    return 0;
  }

  return rm;
}
int elh_iterate_patched_words__xany__UTF8(const char *buf, size_t bufsize, lh_word_check_t *check, lh_word_patch_t *patch, lh_word_callback_t *callback, void *userdata)
{
  unichar check_buf[WORD_MAX_CHARS];
  int prop;
  const char *curr = buf;
  const char *buf_end = buf+bufsize;
  const char *word_begin = curr;
  const char *word_end = NULL;
  unichar uchr;
  size_t word_length;
  unichar patch_buf[WORD_MAX_CHARS];
  const unichar *arg_begin;
  size_t arg_length;
  char word_buf[BUFSIZEOF__UTF8_WORD];
  char *hugeword_buf = NULL;
  size_t hugeword_buf_size = 0;
  while (curr < buf_end)
    {
      word_begin = curr;
      uchr = eh_decode_char__UTF8 (&curr, buf_end);
      prop = unichar_getprops (uchr);
      if (prop & UCP_ALPHA)
	{
	  check_buf[0] = uchr;
	  word_length = 1;
	  for(;;)
	    {
	      word_end = curr;
	      uchr = eh_decode_char__UTF8 (&curr, buf_end);
	      if (uchr < 0)
		{
		  if ((UNICHAR_NO_DATA == uchr) || (UNICHAR_BAD_ENCODING == uchr))
		    return uchr;
		  if (UNICHAR_EOD == uchr)
		    break;
		}
	      prop = unichar_getprops (uchr);
	      if (!(prop & UCP_ALPHA))
		break;
	      if (WORD_MAX_CHARS > word_length)
		check_buf[word_length] = uchr;
	      word_length++;
	    }
	  if (WORD_MAX_CHARS < word_length)
	    goto done_word;
	  if (NULL!=check && 0 == check (check_buf, word_length))
	    goto done_word;
	  if (NULL != patch)
	    {
	      if (0 == patch (check_buf, word_length, patch_buf, &arg_length))
		goto done_word;
	      arg_begin = patch_buf;
	    }
	  else
	    {
	      callback ((utf8char *) word_begin, word_end-word_begin, userdata);
	      goto done_word;
	    }
	  word_end = eh_encode_buffer__UTF8 (arg_begin, arg_begin+arg_length, word_buf, word_buf+BUFSIZEOF__UTF8_WORD);
	  if (NULL != word_end)
	    {
	      callback ((utf8char *)(word_buf), word_end-word_buf, userdata);
	      goto done_word;
	    }
	  if (hugeword_buf_size<(word_length*MAX_UTF8_CHAR))
	    {
	      if (hugeword_buf_size)
		dk_free (hugeword_buf, hugeword_buf_size);
	      hugeword_buf_size = word_length*MAX_UTF8_CHAR;
	      hugeword_buf = (char *) dk_alloc (hugeword_buf_size);
	    }
	  word_end = eh_encode_buffer__UTF8 (arg_begin, arg_begin+arg_length, hugeword_buf, hugeword_buf+hugeword_buf_size);
	  callback ((utf8char *)(hugeword_buf), word_end-hugeword_buf, userdata);
done_word:
	  if (prop & UCP_IDEO)
	    goto proc_ideo;
	  continue;
	}
      if (prop & UCP_IDEO)
	{
proc_ideo:
	  check_buf[0] = uchr;
	  if (NULL!=check && 0 == check (check_buf, 1))
	    continue;
	  if (NULL != patch)
	    {
	      if (0 == patch (check_buf, 1, patch_buf, &arg_length))
		continue;
	      arg_begin = patch_buf;
	    }
	  else
	    {
	      callback ((utf8char *) word_begin, curr-word_begin, userdata);
	      continue;
	    }
	  word_end = eh_encode_buffer__UTF8 (arg_begin, arg_begin+arg_length, word_buf, word_buf+BUFSIZEOF__UTF8_WORD);
	  callback ((utf8char *)(word_buf), word_end-word_buf, userdata);
	  continue;
	}
      if ((uchr < 0) && ((UNICHAR_NO_DATA == uchr) || (UNICHAR_BAD_ENCODING == uchr)))
	goto cleanup; /* see below */
    }
  uchr = 0;
cleanup:
  if (hugeword_buf_size)
    dk_free (hugeword_buf, hugeword_buf_size);
  return uchr;
}
/*
 *  The main thread must call this function to convert itself into a thread.
 */
thread_t *
thread_initial (unsigned long stack_size)
{
  int rc;
  thread_t *thr = NULL;

  if (_main_thread)
    return _main_thread;

  /*
   *  Initialize pthread key
   */
#ifndef OLD_PTHREADS
  rc = pthread_key_create (&_key_current, NULL);
#else
  rc = pthread_keycreate (&_key_current, NULL);
#endif
  CKRET (rc);

  /*
   *  Start off with a value of NULL
   */
  rc = pthread_setspecific (_key_current, NULL);
  CKRET (rc);

  /*
   *  Initialize default thread/mutex attributes
   */
#ifndef OLD_PTHREADS
  /* attribute for thread creation */
  rc = pthread_attr_init (&_thread_attr);
  CKRET (rc);

  /* attribute for mutex creation */
  rc = pthread_mutexattr_init (&_mutex_attr);
  CKRET (rc);
#else
  rc = pthread_attr_create (&_thread_attr);
  CKRET (rc);

  rc = pthread_mutexattr_create (&_mutex_attr);
  CKRET (rc);
#endif

#if defined (PTHREAD_PROCESS_PRIVATE) && !defined(oldlinux) && !defined(__FreeBSD__)
  rc = pthread_mutexattr_setpshared (&_mutex_attr, PTHREAD_PROCESS_PRIVATE);
  CKRET (rc);
#endif

#if defined (MUTEX_FAST_NP) && !defined (_AIX)
  rc = pthread_mutexattr_setkind_np (&_mutex_attr, MUTEX_FAST_NP);
  CKRET (rc);
#endif

#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
  rc = pthread_mutexattr_settype (&_mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP);
  CKRET (rc);
#endif

  /*
   *  Allocate a thread structure
   */
  thr = (thread_t *) dk_alloc (sizeof (thread_t));
  memset (thr, 0, sizeof (thread_t));

  assert (_main_thread == NULL);
  _main_thread = thr;

  _sched_init ();

  if (stack_size == 0)
    stack_size = MAIN_STACK_SIZE;

#if (SIZEOF_VOID_P == 8)
  stack_size *= 2;
#endif
#if defined (__x86_64 ) && defined (SOLARIS)
  /*GK: the LDAP on that platform requires that */
  stack_size *= 2;
#endif


  stack_size = ((stack_size / 8192) + 1) * 8192;

  thr->thr_stack_size = stack_size;
  thr->thr_status = RUNNING;
  thr->thr_cv = _alloc_cv ();
  thr->thr_sem = semaphore_allocate (0);
  thr->thr_schedule_sem = semaphore_allocate (0);
  if (thr->thr_cv == NULL)
    goto failed;
  _thread_init_attributes (thr);
  thread_set_priority (thr, NORMAL_PRIORITY);

  rc = pthread_setspecific (_key_current, thr);
  CKRET (rc);

  return thr;

failed:
  if (thr)
    {
      _thread_free_attributes (thr);
      dk_free (thr, sizeof (thread_t));
    }
  return NULL;
}
void LH_ITERATE_WORDS_NAME(const unichar *buf, size_t bufsize, lh_word_check_t *check, lh_word_callback_t *callback, void *userdata)
{
  size_t pos = 0;
  size_t word_start;
  size_t word_length;
  utf8char word_buf[BUFSIZEOF__UTF8_WORD];
  utf8char *hugeword_buf = NULL;
  size_t hugeword_buf_size = 0;
  utf8char *word_end;
  int prop;
#ifdef LH_ITERATOR_DEBUG
  int wordctr = 0, wordcount = LH_COUNT_WORDS_NAME (buf, bufsize, check);
#define wordctr_INC1 wordctr++
#else
#define wordctr_INC1
#endif
  while (pos < bufsize)
    {
      prop = UNICHAR_GETPROPS_EXPN (buf, bufsize, pos);
      if (prop & UCP_ALPHA)
	{
	  word_start = pos;
	  do pos++; while ((pos < bufsize) && (UNICHAR_GETPROPS_EXPN (buf, bufsize, pos) & UCP_ALPHA));
	  word_length = pos - word_start;
	  if (WORD_MAX_CHARS < word_length)
	    continue;
	  if (NULL!=check && 0 == check(buf+word_start, word_length))
	    continue;
	  word_end = (utf8char *)eh_encode_buffer__UTF8 (buf+word_start, buf+pos, (char *)word_buf, (char *)(word_buf+BUFSIZEOF__UTF8_WORD));
	  if (NULL != word_end)
	    {
	      callback (word_buf, word_end-word_buf, userdata);
              wordctr_INC1;
	      continue;
	    }
	  if (hugeword_buf_size<(word_length*MAX_UTF8_CHAR))
	    {
	      if (hugeword_buf_size)
		dk_free (hugeword_buf, hugeword_buf_size);
	      hugeword_buf_size = word_length*MAX_UTF8_CHAR;
	      hugeword_buf = (utf8char *) dk_alloc (hugeword_buf_size);
	    }
	  word_end = (utf8char *)eh_encode_buffer__UTF8 (buf+word_start, buf+pos, (char *)hugeword_buf, (char *)(hugeword_buf+hugeword_buf_size));
	  callback (hugeword_buf, word_end-hugeword_buf, userdata);
          wordctr_INC1;
	  continue;
	}
      if (prop & UCP_IDEO)
	{
	  word_start = pos;
	  pos++;
	  if (NULL!=check && 0 == check(buf+pos-1, 1))
	    continue;
	  word_end = (utf8char *)eh_encode_buffer__UTF8 (buf+word_start, buf+pos, (char *)(word_buf), (char *)(word_buf+BUFSIZEOF__UTF8_WORD));
	  callback (word_buf, word_end-word_buf, userdata);
          wordctr_INC1;
	  continue;
	}
      pos++;
    }
  if (hugeword_buf_size)
    dk_free (hugeword_buf, hugeword_buf_size);
#ifdef LH_ITERATOR_DEBUG
  if (wordctr != wordcount)
    GPF_T;
#endif
}
void LH_ITERATE_PATCHED_WORDS_NAME(const unichar *buf, size_t bufsize, lh_word_check_t *check, lh_word_patch_t *patch, lh_word_callback_t *callback, void *userdata)
{
  size_t pos = 0;
  size_t word_start;
  size_t word_length;
  unichar patch_buf[WORD_MAX_CHARS];
  const unichar *arg_begin;
  size_t arg_length;
  utf8char word_buf[BUFSIZEOF__UTF8_WORD];
  utf8char *hugeword_buf = NULL;
  size_t hugeword_buf_size = 0;
  utf8char *word_end;
  int prop;
#ifdef LH_ITERATOR_DEBUG
  int wordctr = 0, wordcount = LH_COUNT_WORDS_NAME (buf, bufsize, check);
#define wordctr_INC1 wordctr++
#else
#define wordctr_INC1
#endif
  while (pos < bufsize)
    {
      prop = UNICHAR_GETPROPS_EXPN(buf,bufsize,pos);
      if (prop & UCP_ALPHA)
	{
	  word_start = pos;
	  do pos++; while ((pos < bufsize) && (UNICHAR_GETPROPS_EXPN(buf,bufsize,pos) & UCP_ALPHA));
	  word_length = pos - word_start;
	  if (WORD_MAX_CHARS < word_length)
	    continue;
	  if (NULL!=check && 0 == check(buf+word_start, word_length))
	    {
	      DBG_PRINTF_NOISE_WORD(word_start,word_length);
	      continue;
	    }
	  if (NULL != patch)
	    { /* word should be patched */
	      if (0 == patch (buf+word_start, word_length, patch_buf, &arg_length))
		{
		  DBG_PRINTF_PATCH_FAILED(word_start,word_length);
		  continue;
		}
	      arg_begin = patch_buf;
	    }
	  else
	    { /* argument should be taken right from \c buf */
	      arg_begin = buf+word_start;
	      arg_length = word_length;
	    }
	  word_end = (utf8char *)eh_encode_buffer__UTF8 (arg_begin, arg_begin+arg_length, (char *)(word_buf), (char *)(word_buf+BUFSIZEOF__UTF8_WORD));
	  if (NULL != word_end)
	    {
	      callback (word_buf, word_end-word_buf, userdata);
              wordctr_INC1;
	      continue;
	    }
	  if (hugeword_buf_size<(word_length*MAX_UTF8_CHAR))
	    { /* overflow danger detected */
	      if (hugeword_buf_size)
		dk_free (hugeword_buf, hugeword_buf_size);
	      hugeword_buf_size = word_length*MAX_UTF8_CHAR;
	      hugeword_buf = (utf8char *) dk_alloc (hugeword_buf_size);
	    }
	  word_end = (utf8char *)eh_encode_buffer__UTF8 (arg_begin, arg_begin+arg_length, (char *)(hugeword_buf), (char *)(hugeword_buf+hugeword_buf_size));
	  callback (hugeword_buf, word_end-hugeword_buf, userdata);
          wordctr_INC1;
	  continue;
	}
      if (prop & UCP_IDEO)
	{
	  word_start = pos;
	  pos++;
	  word_length = pos - word_start;
	  if (NULL!=check && 0 == check(buf+word_start, word_length))
	    {
	      DBG_PRINTF_NOISE_IDEO(word_start,word_length);
	      continue;
	    }
	  if (NULL != patch)
	    { /* word should be patched */
	      if (0 == patch (buf+word_start, word_length, patch_buf, &arg_length))
		{
		  DBG_PRINTF_IDEO_PATCH_FAILED(word_start,word_length);
		  continue;
		}
	      arg_begin = patch_buf;
	    }
	  else
	    { /* argument should be taken right from \c buf */
	      arg_begin = buf+word_start;
	      arg_length = word_length;
	    }
	  word_end = (utf8char *)eh_encode_buffer__UTF8 (arg_begin, arg_begin+arg_length, (char *)(word_buf), (char *)(word_buf+BUFSIZEOF__UTF8_WORD));
	  callback (word_buf, word_end-word_buf, userdata);
          wordctr_INC1;
	  continue;
	}
      pos++;
    }
  if (hugeword_buf_size)
    dk_free (hugeword_buf, hugeword_buf_size);
#ifdef LH_ITERATOR_DEBUG
  if (wordctr != wordcount)
    GPF_T;
#endif
}