• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2005, 2008 Red Hat, Inc.
2    This file is part of elfutils.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2007.
4 
5    This file is free software; you can redistribute it and/or modify
6    it under the terms of either
7 
8      * the GNU Lesser General Public License as published by the Free
9        Software Foundation; either version 3 of the License, or (at
10        your option) any later version
11 
12    or
13 
14      * the GNU General Public License as published by the Free
15        Software Foundation; either version 2 of the License, or (at
16        your option) any later version
17 
18    or both in parallel, as here.
19 
20    elfutils is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    General Public License for more details.
24 
25    You should have received copies of the GNU General Public License and
26    the GNU Lesser General Public License along with this program.  If
27    not, see <http://www.gnu.org/licenses/>.  */
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 #include <string.h>
34 #include <system.h>
35 #include "libasmP.h"
36 
37 
38 struct buffer
39 {
40   char *buf;
41   size_t len;
42 };
43 
44 
45 static int
buffer_cb(char * str,size_t len,void * arg)46 buffer_cb (char *str, size_t len, void *arg)
47 {
48   struct buffer *buffer = (struct buffer *) arg;
49 
50   if (len > buffer->len)
51     /* Return additional needed space.  */
52     return len - buffer->len;
53 
54   buffer->buf = mempcpy (buffer->buf, str, len);
55   buffer->len = len;
56 
57   return 0;
58 }
59 
60 
61 int
disasm_str(DisasmCtx_t * ctx,const uint8_t ** startp,const uint8_t * end,GElf_Addr addr,const char * fmt,char ** bufp,size_t len,void * symcbarg)62 disasm_str (DisasmCtx_t *ctx, const uint8_t **startp, const uint8_t *end,
63 	    GElf_Addr addr, const char *fmt, char **bufp, size_t len,
64 	    void *symcbarg)
65 {
66   struct buffer buffer = { .buf = *bufp, .len = len };
67 
68   int res = INTUSE(disasm_cb) (ctx, startp, end, addr, fmt, buffer_cb, &buffer,
69 			       symcbarg);
70   *bufp = buffer.buf;
71   return res;
72 }
73