Esempio n. 1
0
void f1 (const char *c)
{
  A *s = (A*) __builtin_malloc (sizeof (A));
  double *p = &s->d;
  s->i = 42;
  __builtin_memcpy (p, c, sizeof (double));
  int j = s->i;
  if (j != 42) __builtin_abort();
}
Esempio n. 2
0
int
main ()
{
  unsigned char input[sizeof data + 16] __attribute__((aligned (16)));
  __builtin_memset (input, 0, sizeof input);
  __builtin_memcpy (input + 1, data, sizeof data);
  bar (input + 1);
  return 0;
}
void
foo (char *p)
{
  volatile int zero = 0;
  __builtin_memcpy (p, "abc", zero);
  /* This generates a __builtin___asan_report_store1 because we pass volatile
     zero length into memcpy.  */
  p[0] = 'd';
}
main()
{
  int i;
  for (i=0;i<max; i++)
    {
      __builtin_memcpy (a, b, size * sizeof (a[0]));
      asm("");
    }
   return 0;
}
Esempio n. 5
0
void
foo (struct B *x)
{
  struct A a;
  if (x->b)
    __builtin_memcpy (&a, x->c, sizeof a);
  else
    a.a = 0;
  bar (a);
}
Esempio n. 6
0
void sha256_sse()
{
    for (int i = 0; i < NBLOCKS; ++i) {
        __builtin_memcpy(hash[i], __sha256_init, 32);
    }

    __sha256_block_t *blk[4] = { &blocks[0], &blocks[1], &blocks[2], &blocks[3] };
    __sha256_hash_t *hsh[4] = { &hash[0], &hash[1], &hash[2], &hash[3] };
    __sha256_int(blk, hsh);
}
Esempio n. 7
0
void X() {
  do {
    char* b;
    Header c;
    if (a)
      c.fork_flags |= 1;
    __builtin_memcpy(b, &c, __builtin_offsetof(Header, data_length));
    b += foo();
  } while (1);
}
Esempio n. 8
0
test (float num)
{
  unsigned int i;

  if (num < 0.0)
    num = 0.0;

  __builtin_memcpy (&i, &num, sizeof(unsigned int));

  return (long double)(unsigned long long) i;
}
Esempio n. 9
0
struct __go_string
__go_string_plus (struct __go_string s1, struct __go_string s2)
{
  int len;
  unsigned char *retdata;
  struct __go_string ret;

  if (s1.__length == 0)
    return s2;
  else if (s2.__length == 0)
    return s1;

  len = s1.__length + s2.__length;
  retdata = runtime_mallocgc (len, FlagNoPointers, 1, 0);
  __builtin_memcpy (retdata, s1.__data, s1.__length);
  __builtin_memcpy (retdata + s1.__length, s2.__data, s2.__length);
  ret.__data = retdata;
  ret.__length = len;
  return ret;
}
Esempio n. 10
0
int
f (int dim, int *b, int *c)
{
    int newcentroid[3][dim];
    int *a = newcentroid[2];
    int i, dist = 0;
    __builtin_memcpy (newcentroid, c, sizeof (newcentroid));
    for (i = 0; i < dim; i++)
        dist += (a[i] - b[i]) * (a[i] - b[i]);
    return dist;
}
Esempio n. 11
0
File: chan.c Progetto: mm120/gcc
uintptr
reflect_makechan(ChanType *t, uint64 size)
{
	void *ret;
	Hchan *c;

	c = runtime_makechan_c(t, size);
	ret = runtime_mal(sizeof(void*));
	__builtin_memcpy(ret, &c, sizeof(void*));
	return (uintptr)ret;
}
Esempio n. 12
0
String
__go_string_plus (String s1, String s2)
{
  int len;
  byte *retdata;
  String ret;

  if (s1.len == 0)
    return s2;
  else if (s2.len == 0)
    return s1;

  len = s1.len + s2.len;
  retdata = runtime_mallocgc (len, FlagNoPointers, 1, 0);
  __builtin_memcpy (retdata, s1.str, s1.len);
  __builtin_memcpy (retdata + s1.len, s2.str, s2.len);
  ret.str = retdata;
  ret.len = len;
  return ret;
}
Esempio n. 13
0
File: pr57003.c Progetto: ds2dev/gcc
foo (void)
{
  unsigned d;
  unsigned short *e;
  if ((d = bar ()))
    {
      e = baz (d * sizeof (unsigned short) + 20);
      __builtin_memcpy (e, b, d * sizeof (unsigned short));
      c = e;
    }
}
Esempio n. 14
0
inline
void
copy7(Uint32 i, TestSignal & ts){
  TestSignal & dst = g_jobBuffer[i];

#if (__GNUC__ >= 3 ) || (__GNUC__ == 2 && __GNUC_MINOR >= 95)
  __builtin_memcpy(&dst.head.data[0], &ts.head.data[0], sizeof(Data7));
#else
  dst.head = ts.head;
#endif
}
Esempio n. 15
0
void bar (char *d, int *off)
{
  typedef struct
  {
    char c;
    V16 char vc;
  } s_t;
  s_t s = { 1,{ 0,11,22,33,44,55,66,77,88,99,101,111,121,131,141,151 }};
  *off = __builtin_offsetof(s_t, vc);
  __builtin_memcpy(d, &s.vc, 16);
}
Esempio n. 16
0
__attribute__((noinline, noclone)) void
foo (int *a)
{
  for (g = 0; g < 32; g++)
    if (f)
      {
        e = d;
        __builtin_memcpy (&b, &e, sizeof (float));
        b = *a;
      }
}
Esempio n. 17
0
extern inline char *
baz (char *x, const char *y)
{
  const char *e = y;
  unsigned long f, g;
  asm ("" : "+c" (f), "+D" (e) : "a" ('\0'), "X" (*e));
  g = e - 1 - y;
  __builtin_memcpy (x, y, g);
  x[g] = '\0';
  return x;
}
void
chanrecv (unsigned char *ch, unsigned char *val, _Bool *pres)
{
  struct __go_channel *channel = (struct __go_channel *) ch;

  if (channel->element_size <= sizeof (uint64_t))
    {
      union
      {
	char b[sizeof (uint64_t)];
	uint64_t v;
      } u;

      if (pres == NULL)
	u.v = __go_receive_small (channel, 0);
      else
	{
	  struct __go_receive_nonblocking_small s;

	  s = __go_receive_nonblocking_small (channel);
	  *pres = s.__success;
	  if (!s.__success)
	    return;
	  u.v = s.__val;
	}

#ifndef WORDS_BIGENDIAN
      __builtin_memcpy (val, u.b, channel->element_size);
#else
      __builtin_memcpy (val, u.b + sizeof (uint64_t) - channel->element_size,
			channel->element_size);
#endif
    }
  else
    {
      if (pres == NULL)
	__go_receive_big (channel, val, 0);
      else
	*pres = __go_receive_nonblocking_big (channel, val);
    }
}
Esempio n. 19
0
__attribute__ ((ms_abi, noinline, noclone)) void
foo (void)
{
  unsigned d;
  unsigned short *e;
  if ((d = bar ()))
    {
      e = baz (d * sizeof (unsigned short) + 20);
      __builtin_memcpy (e, b, d * sizeof (unsigned short));
      c = e;
    }
}
Esempio n. 20
0
void rq_send(rqueue *rq, uint32_t *msg, size_t size)
{
	/* XXX: Can we also avoid allocation + copy?! ---DB */
	uint32_t *clone = malloc((size + 1) * sizeof(uint32_t));
	if (!clone)
		panic("rq_send malloc failed\n");

	clone[0] = (uint32_t) size;
	__builtin_memcpy(&clone[1], msg, size);

	mbox_put((struct mbox *) rq, (uint32_t) clone);
}
Esempio n. 21
0
File: heap_dbg.c Progetto: Gd58/MCF
void __MCF_CRT_HeapDbgValidateBlockBasic(unsigned char **ppRaw, unsigned char *pContents, const void *pRetAddr){
	unsigned char *const pRaw = pContents - GUARD_BAND_SIZE;
	*ppRaw = pRaw;

	const size_t uSize = __MCF_CRT_ReallyGetUsableSize(pRaw) - GUARD_BAND_SIZE * 2;

	void *const *ppGuard1 = (void *const *)pContents;
	void *const *ppGuard2 = (void *const *)(pContents + uSize);
	for(unsigned i = 0; i < GUARD_BAND_SIZE; i += sizeof(void *)){
		--ppGuard1;

		void *pTemp1, *pTemp2;
		__builtin_memcpy(&pTemp1, ppGuard1, sizeof(void *));
		__builtin_memcpy(&pTemp2, ppGuard2, sizeof(void *));
		if((DecodePointer(pTemp1) != ppGuard2) || (DecodePointer(pTemp2) != ppGuard1)){
			MCF_CRT_BailF(L"__MCF_CRT_HeapDbgValidate() 失败:侦测到堆损坏。\n调用返回地址:%p", pRetAddr);
		}

		++ppGuard2;
	}
}
int main (void)
{
  char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE,
                  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p == MAP_FAILED)
    return 0;
  if (munmap (p + 65536, 65536) < 0)
    return 0;
  __builtin_memcpy (p + 65536 - 5, "abcd", 5);
  test (p + 65536 - 5);
  return 0;
}
Esempio n. 23
0
main (void)
{
  char *ptr;
  char *ptr2;
  {
    char my_char[9];
    ptr = &my_char[0];
    __builtin_memcpy (&ptr2, &ptr, sizeof (ptr2));
  }

  *(ptr2+9) = 'c';
}
Esempio n. 24
0
int test1 ()
{
  const char X[8] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
  char buffer[8];
  __builtin_memcpy (buffer, X, 8);
  if (buffer[0] != 'A' || buffer[1] != 'B'
      || buffer[2] != 'C' || buffer[3] != 'D'
      || buffer[4] != 'E' || buffer[5] != 'F'
      || buffer[6] != 'G' || buffer[7] != 'H')
    abort ();
  return 0;
}
Esempio n. 25
0
void *
__go_allocate_trampoline (uintptr_t size, void *closure)
{
  uintptr_t ptr_size;
  uintptr_t full_size;
  unsigned char *ret;

  /* Because the garbage collector only looks at aligned addresses, we
     need to store the closure at an aligned address to ensure that it
     sees it.  */
  ptr_size = sizeof (void *);
  full_size = (((size + ptr_size - 1) / ptr_size) * ptr_size);
  full_size += ptr_size;

  runtime_lock (&trampoline_lock);

  if (full_size < trampoline_page_size - trampoline_page_used)
    trampoline_page = NULL;

  if (trampoline_page == NULL)
    {
      uintptr_t page_size;
      unsigned char *page;

      page_size = getpagesize ();
      __go_assert (page_size >= full_size);
      page = (unsigned char *) runtime_mallocgc (2 * page_size - 1, 0, 0, 0);
      page = (unsigned char *) (((uintptr_t) page + page_size - 1)
				& ~ (page_size - 1));

#ifdef HAVE_SYS_MMAN_H
      {
	int i;

	i = mprotect (page, page_size, PROT_READ | PROT_WRITE | PROT_EXEC);
	__go_assert (i == 0);
      }
#endif

      trampoline_page = page;
      trampoline_page_size = page_size;
      trampoline_page_used = 0;
    }

  ret = trampoline_page + trampoline_page_used;
  trampoline_page_used += full_size;

  runtime_unlock (&trampoline_lock);

  __builtin_memcpy (ret + full_size - ptr_size, &closure, ptr_size);

  return (void *) ret;
}
Esempio n. 26
0
static int
callback (void *data, uintptr_t pc __attribute__ ((unused)),
	  const char *filename, int lineno, const char *function)
{
  struct caller *c = (struct caller *) data;

  if (function == NULL)
    {
      c->fn.str = NULL;
      c->fn.len = 0;
    }
  else
    {
      byte *s;

      c->fn.len = __builtin_strlen (function);
      s = runtime_malloc (c->fn.len);
      __builtin_memcpy (s, function, c->fn.len);
      c->fn.str = s;
    }

  if (filename == NULL)
    {
      c->file.str = NULL;
      c->file.len = 0;
    }
  else
    {
      byte *s;

      c->file.len = __builtin_strlen (filename);
      s = runtime_malloc (c->file.len);
      __builtin_memcpy (s, filename, c->file.len);
      c->file.str = s;
    }

  c->line = lineno;

  return 0;
}
Esempio n. 27
0
void *
__go_map_index (struct __go_map *map, const void *key, _Bool insert)
{
  const struct __go_map_descriptor *descriptor;
  const struct __go_type_descriptor *key_descriptor;
  uintptr_t key_offset;
  _Bool (*equalfn) (const void*, const void*, size_t);
  size_t key_hash;
  size_t key_size;
  size_t bucket_index;
  char *entry;

  descriptor = map->__descriptor;

  key_descriptor = descriptor->__map_descriptor->__key_type;
  key_offset = descriptor->__key_offset;
  key_size = key_descriptor->__size;
  __go_assert (key_size != 0 && key_size != -1UL);
  equalfn = key_descriptor->__equalfn;

  key_hash = key_descriptor->__hashfn (key, key_size);
  bucket_index = key_hash % map->__bucket_count;

  entry = (char *) map->__buckets[bucket_index];
  while (entry != NULL)
    {
      if (equalfn (key, entry + key_offset, key_size))
	return entry + descriptor->__val_offset;
      entry = *(char **) entry;
    }

  if (!insert)
    return NULL;

  if (map->__element_count >= map->__bucket_count)
    {
      __go_map_rehash (map);
      bucket_index = key_hash % map->__bucket_count;
    }

  entry = (char *) __go_alloc (descriptor->__entry_size);
  __builtin_memset (entry, 0, descriptor->__entry_size);

  __builtin_memcpy (entry + key_offset, key, key_size);

  *(char **) entry = map->__buckets[bucket_index];
  map->__buckets[bucket_index] = entry;

  map->__element_count += 1;

  return entry + descriptor->__val_offset;
}
Esempio n. 28
0
void *
SDL_memcpy(void *dst, const void *src, size_t len)
{
#ifdef __GNUC__
    /* Presumably this is well tuned for speed.
       On my machine this is twice as fast as the C code below.
     */
    return __builtin_memcpy(dst, src, len);
#elif defined(HAVE_MEMCPY)
    return memcpy(dst, src, len);
#elif defined(HAVE_BCOPY)
    bcopy(src, dst, len);
    return dst;
#else
    /* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
       using Uint32* pointers, so we need to make sure the pointers are
       aligned before we loop using them.
     */
    if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) {
        /* Do an unaligned byte copy */
        Uint8 *srcp1 = (Uint8 *)src;
        Uint8 *dstp1 = (Uint8 *)dst;

        while (len--) {
            *dstp1++ = *srcp1++;
        }
    } else {
        size_t left = (len % 4);
        Uint32 *srcp4, *dstp4;
        Uint8 *srcp1, *dstp1;

        srcp4 = (Uint32 *) src;
        dstp4 = (Uint32 *) dst;
        len /= 4;
        while (len--) {
            *dstp4++ = *srcp4++;
        }

        srcp1 = (Uint8 *) srcp4;
        dstp1 = (Uint8 *) dstp4;
        switch (left) {
        case 3:
            *dstp1++ = *srcp1++;
        case 2:
            *dstp1++ = *srcp1++;
        case 1:
            *dstp1++ = *srcp1++;
        }
    }
    return dst;
#endif /* __GNUC__ */
}
Esempio n. 29
0
void
foo (unsigned char *x, unsigned char *y, unsigned char *z,
     unsigned char *w, unsigned int v, int u, int t)
{
  int i;
  for (i = 0; i < t; i++)
    {
      memset (z, x[0], v);
      memset (w, y[0], v);
      x += u;
    }
  __builtin_memcpy (z, x, u);
}
Esempio n. 30
-4
File: heap_dbg.c Progetto: Gd58/MCF
unsigned char *__MCF_CRT_HeapDbgAddBlockGuardsBasic(unsigned char *pRaw){
	unsigned char *const pContents = pRaw + GUARD_BAND_SIZE;
	const size_t uSize = __MCF_CRT_ReallyGetUsableSize(pRaw) - GUARD_BAND_SIZE * 2;

	void **ppGuard1 = (void **)pContents;
	void **ppGuard2 = (void **)(pContents + uSize);
	for(unsigned i = 0; i < GUARD_BAND_SIZE; i += sizeof(void *)){
		--ppGuard1;

		void *const pTemp1 = EncodePointer(ppGuard2), *const pTemp2 = EncodePointer(ppGuard1);
		__builtin_memcpy(ppGuard1, &pTemp1, sizeof(void *));
		__builtin_memcpy(ppGuard2, &pTemp2, sizeof(void *));

		++ppGuard2;
	}

	return pContents;
}