Commit ca10f86763f58b7b3667e2ca7d26db3dc810eb20

Authored by aurel32
1 parent ea86e4e6

Remove osdep.c/qemu-img code duplication

(Kevin Wolf)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4191 c046a42c-6fe2-441c-8c8c-71466251a162
Makefile.target
... ... @@ -430,6 +430,7 @@ OBJS+=gdbstub.o
430 430 endif
431 431  
432 432 OBJS+= libqemu.a
  433 +OBJS+= ../libqemu_common.a
433 434  
434 435 # Note: this is a workaround. The real fix is to avoid compiling
435 436 # cpu_signal_handler() in cpu-exec.c.
... ...
cutils.c
... ... @@ -95,3 +95,38 @@ time_t mktimegm(struct tm *tm)
95 95 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
96 96 return t;
97 97 }
  98 +
  99 +void *get_mmap_addr(unsigned long size)
  100 +{
  101 + return NULL;
  102 +}
  103 +
  104 +void qemu_free(void *ptr)
  105 +{
  106 + free(ptr);
  107 +}
  108 +
  109 +void *qemu_malloc(size_t size)
  110 +{
  111 + return malloc(size);
  112 +}
  113 +
  114 +void *qemu_mallocz(size_t size)
  115 +{
  116 + void *ptr;
  117 + ptr = qemu_malloc(size);
  118 + if (!ptr)
  119 + return NULL;
  120 + memset(ptr, 0, size);
  121 + return ptr;
  122 +}
  123 +
  124 +char *qemu_strdup(const char *str)
  125 +{
  126 + char *ptr;
  127 + ptr = qemu_malloc(strlen(str) + 1);
  128 + if (!ptr)
  129 + return NULL;
  130 + strcpy(ptr, str);
  131 + return ptr;
  132 +}
... ...
... ... @@ -35,6 +35,7 @@
35 35  
36 36 #include "cpu.h"
37 37 #include "exec-all.h"
  38 +#include "qemu-common.h"
38 39 #if defined(CONFIG_USER_ONLY)
39 40 #include <qemu.h>
40 41 #endif
... ...
... ... @@ -40,6 +40,7 @@
40 40  
41 41 #include "cpu.h"
42 42 #include "exec-all.h"
  43 +#include "qemu-common.h"
43 44  
44 45 #ifdef USE_KQEMU
45 46  
... ...
linux-user/main.c
... ... @@ -25,6 +25,7 @@
25 25 #include <unistd.h>
26 26  
27 27 #include "qemu.h"
  28 +#include "qemu-common.h"
28 29  
29 30 #define DEBUG_LOGFILE "/tmp/qemu.log"
30 31  
... ...
... ... @@ -45,21 +45,6 @@
45 45 #include <malloc.h>
46 46 #endif
47 47  
48   -void *get_mmap_addr(unsigned long size)
49   -{
50   - return NULL;
51   -}
52   -
53   -void qemu_free(void *ptr)
54   -{
55   - free(ptr);
56   -}
57   -
58   -void *qemu_malloc(size_t size)
59   -{
60   - return malloc(size);
61   -}
62   -
63 48 #if defined(_WIN32)
64 49 void *qemu_memalign(size_t alignment, size_t size)
65 50 {
... ... @@ -217,26 +202,6 @@ void qemu_vfree(void *ptr)
217 202  
218 203 #endif
219 204  
220   -void *qemu_mallocz(size_t size)
221   -{
222   - void *ptr;
223   - ptr = qemu_malloc(size);
224   - if (!ptr)
225   - return NULL;
226   - memset(ptr, 0, size);
227   - return ptr;
228   -}
229   -
230   -char *qemu_strdup(const char *str)
231   -{
232   - char *ptr;
233   - ptr = qemu_malloc(strlen(str) + 1);
234   - if (!ptr)
235   - return NULL;
236   - strcpy(ptr, str);
237   - return ptr;
238   -}
239   -
240 205 int qemu_create_pidfile(const char *filename)
241 206 {
242 207 char buffer[128];
... ...
... ... @@ -47,17 +47,10 @@
47 47  
48 48 #define qemu_printf printf
49 49  
50   -void *qemu_malloc(size_t size);
51   -void *qemu_mallocz(size_t size);
52   -void qemu_free(void *ptr);
53   -char *qemu_strdup(const char *str);
54   -
55 50 void *qemu_memalign(size_t alignment, size_t size);
56 51 void *qemu_vmalloc(size_t size);
57 52 void qemu_vfree(void *ptr);
58 53  
59   -void *get_mmap_addr(unsigned long size);
60   -
61 54 int qemu_create_pidfile(const char *filename);
62 55  
63 56 #ifdef _WIN32
... ...
qemu-common.h
... ... @@ -86,6 +86,14 @@ int strstart(const char *str, const char *val, const char **ptr);
86 86 int stristart(const char *str, const char *val, const char **ptr);
87 87 time_t mktimegm(struct tm *tm);
88 88  
  89 +void *qemu_malloc(size_t size);
  90 +void *qemu_mallocz(size_t size);
  91 +void qemu_free(void *ptr);
  92 +char *qemu_strdup(const char *str);
  93 +
  94 +void *get_mmap_addr(unsigned long size);
  95 +
  96 +
89 97 /* Error handling. */
90 98  
91 99 void hw_error(const char *fmt, ...)
... ...
qemu-img.c
... ... @@ -30,41 +30,6 @@
30 30 #include <windows.h>
31 31 #endif
32 32  
33   -void *get_mmap_addr(unsigned long size)
34   -{
35   - return NULL;
36   -}
37   -
38   -void qemu_free(void *ptr)
39   -{
40   - free(ptr);
41   -}
42   -
43   -void *qemu_malloc(size_t size)
44   -{
45   - return malloc(size);
46   -}
47   -
48   -void *qemu_mallocz(size_t size)
49   -{
50   - void *ptr;
51   - ptr = qemu_malloc(size);
52   - if (!ptr)
53   - return NULL;
54   - memset(ptr, 0, size);
55   - return ptr;
56   -}
57   -
58   -char *qemu_strdup(const char *str)
59   -{
60   - char *ptr;
61   - ptr = qemu_malloc(strlen(str) + 1);
62   - if (!ptr)
63   - return NULL;
64   - strcpy(ptr, str);
65   - return ptr;
66   -}
67   -
68 33 static void __attribute__((noreturn)) error(const char *fmt, ...)
69 34 {
70 35 va_list ap;
... ...
target-alpha/translate.c
... ... @@ -26,6 +26,7 @@
26 26 #include "exec-all.h"
27 27 #include "disas.h"
28 28 #include "tcg-op.h"
  29 +#include "qemu-common.h"
29 30  
30 31 #define DO_SINGLE_STEP
31 32 #define GENERATE_NOP
... ...
target-arm/helper.c
... ... @@ -6,6 +6,7 @@
6 6 #include "exec-all.h"
7 7 #include "gdbstub.h"
8 8 #include "helpers.h"
  9 +#include "qemu-common.h"
9 10  
10 11 static uint32_t cortexa8_cp15_c0_c1[8] =
11 12 { 0x1031, 0x11, 0x400, 0, 0x31100003, 0x20000000, 0x01202000, 0x11 };
... ...
target-cris/translate.c
... ... @@ -32,6 +32,7 @@
32 32 #include "tcg-op.h"
33 33 #include "helper.h"
34 34 #include "crisv32-decode.h"
  35 +#include "qemu-common.h"
35 36  
36 37 #define CRIS_STATS 0
37 38 #if CRIS_STATS
... ...
target-i386/helper2.c
... ... @@ -28,6 +28,7 @@
28 28 #include "cpu.h"
29 29 #include "exec-all.h"
30 30 #include "svm.h"
  31 +#include "qemu-common.h"
31 32  
32 33 //#define DEBUG_MMU
33 34  
... ...
target-m68k/helper.c
... ... @@ -25,6 +25,7 @@
25 25 #include "config.h"
26 26 #include "cpu.h"
27 27 #include "exec-all.h"
  28 +#include "qemu-common.h"
28 29  
29 30 enum m68k_cpuid {
30 31 M68K_CPUID_M5206,
... ...
target-mips/translate.c
... ... @@ -30,6 +30,7 @@
30 30 #include "exec-all.h"
31 31 #include "disas.h"
32 32 #include "tcg-op.h"
  33 +#include "qemu-common.h"
33 34  
34 35 //#define MIPS_DEBUG_DISAS
35 36 //#define MIPS_DEBUG_SIGN_EXTENSIONS
... ...
target-ppc/helper.c
... ... @@ -28,6 +28,7 @@
28 28 #include "cpu.h"
29 29 #include "exec-all.h"
30 30 #include "helper_regs.h"
  31 +#include "qemu-common.h"
31 32  
32 33 //#define DEBUG_MMU
33 34 //#define DEBUG_BATS
... ...
target-ppc/translate.c
... ... @@ -27,6 +27,7 @@
27 27 #include "exec-all.h"
28 28 #include "disas.h"
29 29 #include "tcg-op.h"
  30 +#include "qemu-common.h"
30 31  
31 32 /* Include definitions for instructions classes and implementations flags */
32 33 //#define DO_SINGLE_STEP
... ...
target-sh4/translate.c
... ... @@ -32,6 +32,7 @@
32 32 #include "exec-all.h"
33 33 #include "disas.h"
34 34 #include "tcg-op.h"
  35 +#include "qemu-common.h"
35 36  
36 37 typedef struct DisasContext {
37 38 struct TranslationBlock *tb;
... ...
target-sparc/helper.c
... ... @@ -27,6 +27,7 @@
27 27  
28 28 #include "cpu.h"
29 29 #include "exec-all.h"
  30 +#include "qemu-common.h"
30 31  
31 32 //#define DEBUG_MMU
32 33  
... ...
tcg/tcg.c
... ... @@ -39,7 +39,7 @@
39 39 #endif
40 40  
41 41 #include "config.h"
42   -#include "osdep.h"
  42 +#include "qemu-common.h"
43 43  
44 44 /* Note: the long term plan is to reduce the dependancies on the QEMU
45 45 CPU definitions. Currently they are used for qemu_ld/st
... ... @@ -147,36 +147,6 @@ int gen_new_label(void)
147 147  
148 148 #include "tcg-target.c"
149 149  
150   -/* XXX: factorize */
151   -static void pstrcpy(char *buf, int buf_size, const char *str)
152   -{
153   - int c;
154   - char *q = buf;
155   -
156   - if (buf_size <= 0)
157   - return;
158   -
159   - for(;;) {
160   - c = *str++;
161   - if (c == 0 || q >= buf + buf_size - 1)
162   - break;
163   - *q++ = c;
164   - }
165   - *q = '\0';
166   -}
167   -
168   -#if TCG_TARGET_REG_BITS == 32
169   -/* strcat and truncate. */
170   -static char *pstrcat(char *buf, int buf_size, const char *s)
171   -{
172   - int len;
173   - len = strlen(buf);
174   - if (len < buf_size)
175   - pstrcpy(buf + len, buf_size - len, s);
176   - return buf;
177   -}
178   -#endif
179   -
180 150 /* pool based memory allocation */
181 151 void *tcg_malloc_internal(TCGContext *s, int size)
182 152 {
... ...