Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
	char *dst;
	char *src;

	START(argc, argv, "pmem_movnt");

	src = MEMALIGN(64, 8192);
	dst = MEMALIGN(64, 8192);

	memset(src, 0x88, 8192);
	memset(dst, 0, 8192);

	for (size_t size = 1; size <= 4096; size *= 2) {
		memset(dst, 0, 4096);
		pmem_memcpy_nodrain(dst, src, size);
		ASSERTeq(memcmp(src, dst, size), 0);
		ASSERTeq(dst[size], 0);
	}

	for (size_t size = 1; size <= 4096; size *= 2) {
		memset(dst, 0, 4096);
		pmem_memmove_nodrain(dst, src, size);
		ASSERTeq(memcmp(src, dst, size), 0);
		ASSERTeq(dst[size], 0);
	}

	for (size_t size = 1; size <= 4096; size *= 2) {
		memset(dst, 0, 4096);
		pmem_memset_nodrain(dst, 0x77, size);
		ASSERTeq(dst[0], 0x77);
		ASSERTeq(dst[size - 1], 0x77);
		ASSERTeq(dst[size], 0);
	}

	FREE(dst);
	FREE(src);

	DONE(NULL);
}
Ejemplo n.º 2
0
void ParticleTest::Draw( bln is_stepTwo )
{
	for( PSystem &ps : _psystems )
	{
		for( PSystem::CS &cs : ps.csStack )
		{
			cs.uniforms->DrawDebugInfo( is_stepTwo );
		}
	}

	if( is_stepTwo == false )
	{
		return;
	}

	RendererGlobals::i_ImContext->CSSetUnorderedAccessViews( 0, 1, _frameDataUAV.Addr(), 0 );
	RendererGlobals::i_ImContext->CSSetShader( _eraseFrameDataCS.get(), 0, 0 );
	RendererGlobals::i_ImContext->Dispatch( (UINT)MEMALIGN( (_particlesCount + _meshVerticesCount), 64 ) / 64, 1, 1 );

	ID3D11UnorderedAccessView *resetUAVs[ 3 ] = {};
	RendererGlobals::i_ImContext->CSSetUnorderedAccessViews( 0, 3, resetUAVs, 0 );

	RendererGlobals::i_ImContext->CSSetConstantBuffers( 0, 1, _uniBuffer.Addr() );
	RendererGlobals::i_ImContext->CSSetConstantBuffers( 13, 1, &RendererGlobals::ai_VSShaderRegisters[ 13 ] );
			
	RendererGlobals::i_ImContext->CSSetUnorderedAccessViews( 0, 1, _particlesVBUAV.Addr(), 0 );
	RendererGlobals::i_ImContext->CSSetUnorderedAccessViews( 1, 1, _frameDataUAV.Addr(), 0 );

	for( PSystem &ps : _psystems )
	{
		for( PSystem::CS &cs : ps.csStack )
		{
			RendererGlobals::i_ImContext->CSSetShader( cs.uniforms->GetComputeShader(), 0, 0 );
			ui32 start = ps.start;
			if( ps.type == PSystemType::Mesh )
			{
				start += _particlesCount;
			}
			cs.uniforms->SetUniformsAndUAVs( _uniBuffer, start );
			RendererGlobals::i_ImContext->Dispatch( ps.count / 64, 1, 1 );
		}
	}

	RendererGlobals::i_ImContext->CSSetUnorderedAccessViews( 0, 3, resetUAVs, 0 );

	DrawAllParticles();

	DrawAllMeshes();
}
Ejemplo n.º 3
0
/**
 * Performs a "deep" copy of a hostent into a buffer (returns a pointer to the
 * copy). Make absolutely sure the destination buffer is big enough!
 *
 * Keith McGuigan 
 * 10/3/2001 */
static struct hostent* pack_hostent(char* buf, struct hostent* orig)
{
  char* bufptr;
  struct hostent* copy;

  int i;
  char* str;
  int len;

  bufptr = buf;
  copy = (struct hostent*)bufptr;

  bufptr += sizeof(struct hostent);
  copy->h_name = bufptr;
  len = strlen(orig->h_name) + 1;
  strncpy(bufptr, orig->h_name, len);
  bufptr += len;

  /* we align on even 64bit boundaries for safety */
#define MEMALIGN(x) (((unsigned long)(x)&0xfffffff8)+8)

  /* This must be aligned properly to work on many CPU architectures! */
  copy->h_aliases = (char**)MEMALIGN(bufptr);

  /* Figure out how many aliases there are */
  for (i = 0; orig->h_aliases[i] != NULL; ++i);

  /* Reserve room for the array */
  bufptr += (i + 1) * sizeof(char*);

  /* Clone all known aliases */
  for(i = 0; (str = orig->h_aliases[i]); i++) {
    len = strlen(str) + 1;
    strncpy(bufptr, str, len);
    copy->h_aliases[i] = bufptr;
    bufptr += len;
  }
  /* Terminate the alias list with a NULL */
  copy->h_aliases[i] = NULL;

  copy->h_addrtype = orig->h_addrtype;
  copy->h_length = orig->h_length;
    
  /* align it for (at least) 32bit accesses */
  bufptr = (char *)MEMALIGN(bufptr);

  copy->h_addr_list = (char**)bufptr;

  /* Figure out how many addresses there are */
  for (i = 0; orig->h_addr_list[i] != NULL; ++i);

  /* Reserve room for the array */
  bufptr += (i + 1) * sizeof(char*);

  i = 0;
  len = orig->h_length;
  str = orig->h_addr_list[i];
  while (str != NULL) {
    memcpy(bufptr, str, len);
    copy->h_addr_list[i] = bufptr;
    bufptr += len;
    str = orig->h_addr_list[++i];
  }
  copy->h_addr_list[i] = NULL;

  return copy;
}
Ejemplo n.º 4
0
/*
 * Performs a "deep" copy of a hostent into a buffer (returns a pointer to the
 * copy). Make absolutely sure the destination buffer is big enough!
 */
static struct hostent* pack_hostent(char** buf, struct hostent* orig)
{
  char *bufptr;
  char *newbuf;
  struct hostent* copy;

  int i;
  char *str;
  size_t len;

  bufptr = *buf;
  copy = (struct hostent*)bufptr;

  bufptr += sizeof(struct hostent);
  copy->h_name = bufptr;
  len = strlen(orig->h_name) + 1;
  strncpy(bufptr, orig->h_name, len);
  bufptr += len;

  /* we align on even 64bit boundaries for safety */
#define MEMALIGN(x) ((x)+(8-(((unsigned long)(x))&0x7)))

  /* This must be aligned properly to work on many CPU architectures! */
  bufptr = MEMALIGN(bufptr);
  
  copy->h_aliases = (char**)bufptr;

  /* Figure out how many aliases there are */
  for (i = 0; orig->h_aliases && orig->h_aliases[i]; ++i);

  /* Reserve room for the array */
  bufptr += (i + 1) * sizeof(char*);

  /* Clone all known aliases */
  if(orig->h_aliases) {
    for(i = 0; (str = orig->h_aliases[i]); i++) {
      len = strlen(str) + 1;
      strncpy(bufptr, str, len);
      copy->h_aliases[i] = bufptr;
      bufptr += len;
    }
  }
  /* if(!orig->h_aliases) i was already set to 0 */

  /* Terminate the alias list with a NULL */
  copy->h_aliases[i] = NULL;

  copy->h_addrtype = orig->h_addrtype;
  copy->h_length = orig->h_length;
    
  /* align it for (at least) 32bit accesses */
  bufptr = MEMALIGN(bufptr);

  copy->h_addr_list = (char**)bufptr;

  /* Figure out how many addresses there are */
  for (i = 0; orig->h_addr_list[i] != NULL; ++i);

  /* Reserve room for the array */
  bufptr += (i + 1) * sizeof(char*);

  i = 0;
  len = orig->h_length;
  str = orig->h_addr_list[i];
  while (str != NULL) {
    memcpy(bufptr, str, len);
    copy->h_addr_list[i] = bufptr;
    bufptr += len;
    str = orig->h_addr_list[++i];
  }
  copy->h_addr_list[i] = NULL;

  /* now, shrink the allocated buffer to the size we actually need, which
     most often is only a fraction of the original alloc */
  newbuf=(char *)realloc(*buf, (long)bufptr-(long)(*buf));

  /* if the alloc moved, we need to adjust things again */
  if(newbuf != *buf)
    hostcache_fixoffset((struct hostent*)newbuf, (long)newbuf-(long)*buf);

  /* setup the return */
  *buf = newbuf;
  copy = (struct hostent*)newbuf;

  return copy;
}
Ejemplo n.º 5
0
/*
 * Hmm, we don't have a gethostbyname_r(), this is bad...
 * Here we must perform a "deep-copy" of a hostent struct returned
 * from gethostbyname.
 * Note: Bellow code is based on parts from cURL.
 */
int gw_gethostbyname(struct hostent *ent, const char *name, char **buff)
{
    int len, i;
    struct hostent *p;
    /* Allocate enough memory to hold the full name information structs and
     * everything. OSF1 is known to require at least 8872 bytes. The buffer
     * required for storing all possible aliases and IP numbers is according to
     * Stevens' Unix Network Programming 2nd editor, p. 304: 8192 bytes!
     */
    size_t bufflen = 9000;
    char *bufptr, *str;

    lock(GETHOSTBYNAME);

    p = gethostbyname(name);
    if (p == NULL) {
        unlock(GETHOSTBYNAME);
        *buff = NULL;
        return -1;
    }

    *ent = *p;
    /* alloc mem */
    bufptr = *buff = gw_malloc(bufflen);
    ent->h_name = bufptr;
    /* copy h_name into buff */
    len = strlen(p->h_name) + 1;
    strncpy(bufptr, p->h_name, len);
    bufptr += len;

  /* we align on even 64bit boundaries for safety */
#define MEMALIGN(x) ((x)+(8-(((unsigned long)(x))&0x7)))

    /* This must be aligned properly to work on many CPU architectures! */
    bufptr = MEMALIGN(bufptr);

    ent->h_aliases = (char**)bufptr;

    /* Figure out how many aliases there are */
    for (i = 0; p->h_aliases[i] != NULL; ++i)
        ;

    /* Reserve room for the array */
    bufptr += (i + 1) * sizeof(char*);

    /* Clone all known aliases */
    for(i = 0; (str = p->h_aliases[i]); i++) {
        len = strlen(str) + 1;
        strncpy(bufptr, str, len);
        ent->h_aliases[i] = bufptr;
        bufptr += len;
    }
    /* Terminate the alias list with a NULL */
    ent->h_aliases[i] = NULL;

    ent->h_addrtype = p->h_addrtype;
    ent->h_length = p->h_length;

    /* align it for (at least) 32bit accesses */
    bufptr = MEMALIGN(bufptr);

    ent->h_addr_list = (char**)bufptr;

    /* Figure out how many addresses there are */
    for (i = 0; p->h_addr_list[i] != NULL; ++i)
        ;

    /* Reserve room for the array */
    bufptr += (i + 1) * sizeof(char*);

    i = 0;
    len = p->h_length;
    str = p->h_addr_list[i];
    while (str != NULL) {
        memcpy(bufptr, str, len);
        ent->h_addr_list[i] = bufptr;
        bufptr += len;
        str = p->h_addr_list[++i];
    }
    ent->h_addr_list[i] = NULL;

#undef MEMALIGN

    unlock(GETHOSTBYNAME);

    return 0;
}