| 218 | /****************************************************/ |
| 219 | |
| 220 | extern "C" void* mc_malloc(size_t size) |
| 221 | { |
| 222 | if(size == 0) { |
| 223 | return nullptr; |
| 224 | } |
| 225 | |
| 226 | if(allocationLimit != 0 && stats.current + size > allocationLimit) { |
| 227 | log("malloc(%u) -> exceeds maximum (current is %u bytes)", size, stats.current); |
| 228 | return nullptr; |
| 229 | } |
| 230 | |
| 231 | /* call read malloc procedure in libc */ |
| 232 | void* ret = REAL(F_MALLOC)(alignment + size); |
| 233 | |
| 234 | if(ret == nullptr) { |
| 235 | log("malloc(%u) failed", size); |
| 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | /* prepend allocation size and check sentinel */ |
| 240 | *static_cast<size_t*>(ret) = size; |
| 241 | ret = offsetPointer(ret, alignment); |
| 242 | *getSentinel(ret) = sentinel; |
| 243 | |
| 244 | inc_count(size); |
| 245 | if(size >= logThreshold) { |
| 246 | log("malloc(%u) = %p (cur %u)", size, ret, stats.current); |
| 247 | } |
| 248 | |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | extern "C" void* mc_zalloc(size_t size) |
| 253 | { |
no test coverage detected