The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
wrapper.c
Go to the documentation of this file.
1 
30 #include <stdlib.h>
31 #include <string.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 
35 #include <core/timer.h>
36 #include <core/init.h>
37 #include <scheduler/scheduler.h>
38 #include <mm/dymelor.h>
39 
40 // Definitions to functions which will be wrapped by the linker
41 char *__real_strcpy(char *, const char *);
42 char *__real_strncpy(char *, const char *, size_t);
43 char *__real_strcat(char *, const char *);
44 char *__real_strncat(char *, const char *, size_t);
45 void *__real_memcpy(void *, const void *, size_t);
46 void *__real_memmove(void *, const void *, size_t);
47 void *__real_memset(void *, int, size_t);
48 size_t __real_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
49 int __real_fputc(int c, FILE *stream);
50 int __real_fputs(const char *s, FILE *stream);
51 int __real_vfprintf(FILE *stream, const char *format, va_list ap);
52 
53 
54 /* memory-related wrappers */
55 
56 char *__wrap_strcpy(char *s, const char *ct)
57 {
58  dirty_mem(s, -1);
59  return __real_strcpy(s, ct);
60 }
61 
62 char *__wrap_strncpy(char *s, const char *ct, size_t n)
63 {
64  dirty_mem((void *)s, n);
65  return __real_strncpy(s, ct, n);
66 }
67 
68 char *__wrap_strcat(char *s, const char *ct)
69 {
70  dirty_mem(s, -1);
71  return __real_strcat(s, ct);
72 }
73 
74 char *__wrap_strncat(char *s, const char *ct, size_t n)
75 {
76  dirty_mem(s, n);
77  return __real_strncat(s, ct, n);
78 }
79 
80 void *__wrap_memcpy(void *s, const void *ct, size_t n)
81 {
82  dirty_mem(s, n);
83  return __real_memcpy(s, ct, n);
84 }
85 
86 void *__wrap_memmove(void *s, const void *ct, size_t n)
87 {
88  dirty_mem(s, n);
89  return __real_memmove(s, ct, n);
90 }
91 
92 void *__wrap_memset(void *s, int c, size_t n)
93 {
94  dirty_mem(s, n);
95  return __real_memset(s, c, n);
96 }
97 
98 void __wrap_bzero(void *s, size_t n) {
99  __wrap_memset(s, 0, n);
100 }
101 
102 char *__wrap_strdup(const char *s)
103 {
104  char *ret = (char *)__wrap_malloc(strlen(s) + 1);
105  __real_strcpy(ret, s);
106  dirty_mem(ret, strlen(s));
107  return ret;
108 }
109 
110 char *__wrap_strndup(const char *s, size_t n)
111 {
112  char *ret = (char *)__wrap_malloc(n);
113  __real_strncpy(ret, s, n);
114  dirty_mem(ret, n);
115  return ret;
116 }
117 
118 /* stdio.h wrappers */
119 
120 inline int __wrap_vfprintf(FILE *stream, const char *format, va_list ap)
121 {
122  int ret = 0;
123 
124  if(!rootsim_config.silent_output || stream != stdout)
125  ret = __real_vfprintf(stream, format, ap);
126 
127  return ret;
128 }
129 
130 int __wrap_vprintf(const char *format, va_list ap)
131 {
132  return __wrap_vfprintf(stdout, format, ap);
133 }
134 
135 int __wrap_printf(const char *format, ...)
136 {
137  int ret = 0;
138  va_list args;
139  va_start(args, format);
140 
141  ret = __wrap_vfprintf(stdout, format, args);
142 
143  va_end(args);
144  return ret;
145 }
146 
147 int __wrap_fprintf(FILE *stream, const char *format, ...)
148 {
149  int ret = 0;
150  va_list args;
151  va_start(args, format);
152 
153  ret = __wrap_vfprintf(stream, format, args);
154 
155  va_end(args);
156  return ret;
157 }
158 
159 inline int __wrap_fputs(const char *s, FILE *stream)
160 {
161  int ret = 0;
162 
163  if(!rootsim_config.silent_output || stream != stdout)
164  ret = __real_fputs(s, stream);
165 
166  return ret;
167 }
168 
169 int __wrap_puts(const char *s)
170 {
171  int ret = 0;
172 
173  ret += __wrap_fputs(s, stdout);
174  ret += __wrap_fputs("\n", stdout); // puts() writes the string s and a trailing newline to stdout.
175 
176  return ret;
177 }
178 
179 size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
180 {
181  if(stream == stdout && rootsim_config.silent_output)
182  return 0;
183  return __real_fwrite(ptr, size, nmemb, stream);
184 }
185 
186 inline int __wrap_fputc(int c, FILE *stream)
187 {
188  int ret = 0;
189 
190  if(!rootsim_config.silent_output || stream != stdout)
191  ret = __real_fputc(c, stream);
192 
193  return ret;
194 }
195 
196 int __wrap_putc(int c, FILE *stream)
197 {
198  return __wrap_fputc(c, stream);
199 }
200 
201 int __wrap_putchar(int c)
202 {
203  return __wrap_fputc(c, stdout);
204 }
Initialization routines.
void dirty_mem(void *base, int size)
Definition: dymelor.c:445
Dynamic Memory Logger and Restorer (DyMeLoR)
Timers.
The ROOT-Sim scheduler main module header.
simulation_configuration rootsim_config
This global variable holds the configuration for the current simulation.
Definition: core.c:70
bool silent_output
Disable any output generated by printf() calls.
Definition: init.h:75
void * __wrap_malloc(size_t size)
Definition: dymelor.c:553