FreeBSD/contrib/binutils/bfd/elf.c
/* Function: elfcore_write_note

   Inputs:
     buffer to hold note, and current size of buffer
     name of note
     type of note
     data for note
     size of data for note

   Writes note to end of buffer.  ELF64 notes are written exactly as
   for ELF32, despite the current (as of 2006) ELF gabi specifying
   that they ought to have 8-byte namesz and descsz field, and have
   8-byte alignment.  Other writers, eg. Linux kernel, do the same.

   Return:
   Pointer to realloc'd buffer, *BUFSIZ updated.  */
elfcore_write_note
Inputs:
buffer to hold note, and current size of buffer
name of note
type of note
data for note
size of data for note

Writes note to end of buffer.  ELF64 notes are written exactly as
for ELF32, despite the current (as of 2006) ELF gabi specifying
that they ought to have 8-byte namesz and descsz field, and have
8-byte alignment.  Other writers, eg. Linux kernel, do the same.

Pointer to realloc'd buffer, *BUFSIZ updated.
elfcore_write_note Inputs : buffer to hold note and current size of buffer name of note type of note data for note size of data for note Writes note to end of buffer . ELF64 notes are written exactly as for ELF32 despite the current ( as of 2006 ) ELF gabi specifying that they ought to have 8 - byte namesz and descsz field and have 8 - byte alignment . Other writers eg . Linux kernel do the same . Pointer to realloc ' d buffer * BUFSIZ updated .
char *
elfcore_write_note (bfd *abfd,
		    char *buf,
		    int *bufsiz,
		    const char *name,
		    int type,
		    const void *input,
		    int size)
{
  Elf_External_Note *xnp;
  size_t namesz;
  size_t newspace;
  char *dest;
  namesz = 0;
  if (name != NULL)
    namesz = strlen (name) + 1;
  newspace = 12 + ((namesz + 3) & -4) + ((size + 3) & -4);
  buf = realloc (buf, *bufsiz + newspace);
  dest = buf + *bufsiz;
  *bufsiz += newspace;
  xnp = (Elf_External_Note *) dest;
  H_PUT_32 (abfd, namesz, xnp->namesz);
  H_PUT_32 (abfd, size, xnp->descsz);
  H_PUT_32 (abfd, type, xnp->type);
  dest = xnp->name;
  if (name != NULL)
    {
      memcpy (dest, name, namesz);
      dest += namesz;
      while (namesz & 3)
	{
	  *dest++ = '\0';
	  ++namesz;
	}
    }
  memcpy (dest, input, size);
  dest += size;
  while (size & 3)
    {
      *dest++ = '\0';
      ++size;
    }
  return buf;
}
char * elfcore_write_note ( bfd * abfd , char * buf , int * bufsiz , const char * name , int type , const void * input , int size ) { Elf_External_Note * xnp ; size_t namesz ; size_t newspace ; char * dest ; namesz = 0 ; if ( name != NULL ) namesz = strlen ( name ) + 1 ; newspace = 12 + ( ( namesz + 3 ) & -4 ) + ( ( size + 3 ) & -4 ) ; buf = realloc ( buf , * bufsiz + newspace ) ; dest = buf + * bufsiz ; * bufsiz += newspace ; xnp = ( Elf_External_Note * ) dest ; H_PUT_32 ( abfd , namesz , xnp -> namesz ) ; H_PUT_32 ( abfd , size , xnp -> descsz ) ; H_PUT_32 ( abfd , type , xnp -> type ) ; dest = xnp -> name ; if ( name != NULL ) { memcpy ( dest , name , namesz ) ; dest += namesz ; while ( namesz & 3 ) { * dest ++ = ' \0 ' ; ++ namesz ; } } memcpy ( dest , input , size ) ; dest += size ; while ( size & 3 ) { * dest ++ = ' \0 ' ; ++ size ; } return buf ; }
Function: elfcore_write_note
Inputs:
buffer to hold note, and current size of buffer
name of note
type of note
data for note
size of data for note
Function : elfcore_write_note Inputs : buffer to hold note and current size of buffer name of note type of note data for note size of data for note