mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
* Paranoia checks were accidentally globally enabled by default. Object
* cache paranoia was always enabled. * Changed from paranoia on/off to levels. Adjusted the macros to take a level argument. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25215 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2651d14422
commit
97c0a2b3f1
@ -4,7 +4,7 @@
|
||||
|
||||
// enable paranoia checks (0/1)
|
||||
#ifndef ENABLE_PARANOIA_CHECKS
|
||||
# define ENABLE_PARANOIA_CHECKS 1
|
||||
# define ENABLE_PARANOIA_CHECKS 0
|
||||
#endif
|
||||
|
||||
// number of check slots (should depend on the components for which checks
|
||||
@ -12,9 +12,15 @@
|
||||
#define PARANOIA_SLOT_COUNT (32 * 1024)
|
||||
|
||||
|
||||
// macros that enable paranoia checks for individual components
|
||||
// macros that set the paranoia check level for individual components
|
||||
// levels:
|
||||
// * PARANOIA_NAIVE (checks disabled)
|
||||
// * PARANOIA_SUSPICIOUS
|
||||
// * PARANOIA_OBSESSIVE
|
||||
// * PARANOIA_INSANE
|
||||
|
||||
//#define NET_BUFFER_PARANOIA 1
|
||||
#define NET_BUFFER_PARANOIA PARANOIA_NAIVE
|
||||
#define OBJECT_CACHE_PARANOIA PARANOIA_NAIVE
|
||||
|
||||
|
||||
#endif // DEBUG_PARANOIA_CONFIG_H
|
||||
|
@ -12,15 +12,21 @@
|
||||
#include "paranoia_config.h"
|
||||
|
||||
|
||||
// How to use: Include the header only from source files. Define
|
||||
// ENABLE_PARANOIA_CHECK_COMPONENT (to 1 to enable) before. Use the macros
|
||||
// defined below and the ParanoiaChecker class.
|
||||
// How to use: Include the header only from source files. Set
|
||||
// COMPONENT_PARANOIA_LEVEL before. Use the macros defined below and the
|
||||
// ParanoiaChecker class.
|
||||
|
||||
// paranoia levels
|
||||
#define PARANOIA_NAIVE 0 /* don't do any checks */
|
||||
#define PARANOIA_SUSPICIOUS 1 /* do some checks */
|
||||
#define PARANOIA_OBSESSIVE 2 /* do a lot of checks */
|
||||
#define PARANOIA_INSANE 3 /* do all checks, also very expensive ones */
|
||||
|
||||
// mode for set_paranoia_check()
|
||||
enum paranoia_set_check_mode {
|
||||
PARANOIA_DONT_FAIL,
|
||||
PARANOIA_FAIL_IF_EXISTS,
|
||||
PARANOIA_FAIL_IF_MISSING
|
||||
PARANOIA_DONT_FAIL, // succeed, if check for address exists or not
|
||||
PARANOIA_FAIL_IF_EXISTS, // fail, if check for address already exists
|
||||
PARANOIA_FAIL_IF_MISSING // fail, if check for address doesn't exist yet
|
||||
};
|
||||
|
||||
|
||||
@ -45,10 +51,15 @@ void debug_paranoia_init();
|
||||
__END_DECLS
|
||||
|
||||
|
||||
#if ENABLE_PARANOIA_CHECK_COMPONENT
|
||||
#if COMPONENT_PARANOIA_LEVEL
|
||||
# define PARANOIA_ONLY(x) x
|
||||
# define PARANOIA_ONLY_LEVEL(level, x) \
|
||||
if ((level) <= (COMPONENT_PARANOIA_LEVEL)) { \
|
||||
x; \
|
||||
}
|
||||
#else
|
||||
# define PARANOIA_ONLY(x)
|
||||
# define PARANOIA_ONLY_LEVEL(level, x)
|
||||
#endif
|
||||
|
||||
#define CREATE_PARANOIA_CHECK_SET(object, description) \
|
||||
@ -57,17 +68,22 @@ __END_DECLS
|
||||
PARANOIA_ONLY(delete_paranoia_check_set((object)))
|
||||
#define RUN_PARANOIA_CHECKS(object) \
|
||||
PARANOIA_ONLY(run_paranoia_checks((object)))
|
||||
#define ADD_PARANOIA_CHECK(object, address, size) \
|
||||
PARANOIA_ONLY(set_paranoia_check((object), (address), (size), \
|
||||
PARANOIA_FAIL_IF_EXISTS))
|
||||
#define UPDATE_PARANOIA_CHECK(object, address, size) \
|
||||
PARANOIA_ONLY(set_paranoia_check((object), (address), (size), \
|
||||
PARANOIA_FAIL_IF_MISSING))
|
||||
#define SET_PARANOIA_CHECK(object, address, size) \
|
||||
PARANOIA_ONLY(set_paranoia_check((object), (address), (size), \
|
||||
PARANOIA_DONT_FAIL))
|
||||
#define REMOVE_PARANOIA_CHECK(object, address, size) \
|
||||
PARANOIA_ONLY(remove_paranoia_check((object), (address), (size)))
|
||||
|
||||
#define ADD_PARANOIA_CHECK(level, object, address, size) \
|
||||
PARANOIA_ONLY_LEVEL((level), \
|
||||
set_paranoia_check((object), (address), (size), \
|
||||
PARANOIA_FAIL_IF_EXISTS))
|
||||
#define UPDATE_PARANOIA_CHECK(level, object, address, size) \
|
||||
PARANOIA_ONLY_LEVEL((level), \
|
||||
set_paranoia_check((object), (address), (size), \
|
||||
PARANOIA_FAIL_IF_MISSING))
|
||||
#define SET_PARANOIA_CHECK(level, object, address, size) \
|
||||
PARANOIA_ONLY_LEVEL((level), \
|
||||
set_paranoia_check((object), (address), (size), \
|
||||
PARANOIA_DONT_FAIL))
|
||||
#define REMOVE_PARANOIA_CHECK(level, object, address, size) \
|
||||
PARANOIA_ONLY_LEVEL((level), \
|
||||
remove_paranoia_check((object), (address), (size)))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -40,7 +40,7 @@
|
||||
//#define ENABLE_DEBUGGER_COMMANDS 1
|
||||
#define PARANOID_BUFFER_CHECK NET_BUFFER_PARANOIA
|
||||
|
||||
#define ENABLE_PARANOIA_CHECK_COMPONENT NET_BUFFER_PARANOIA
|
||||
#define COMPONENT_PARANOIA_LEVEL NET_BUFFER_PARANOIA
|
||||
#include <debug_paranoia.h>
|
||||
|
||||
|
||||
@ -467,7 +467,8 @@ create_buffer(size_t headerSpace)
|
||||
|
||||
CHECK_BUFFER(buffer);
|
||||
CREATE_PARANOIA_CHECK_SET(buffer, "net_buffer");
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@ -618,7 +619,8 @@ clone_buffer(net_buffer *_buffer, bool shareFreeSpace)
|
||||
copy_metadata(clone, buffer);
|
||||
|
||||
CREATE_PARANOIA_CHECK_SET(clone, "net_buffer");
|
||||
SET_PARANOIA_CHECK(clone, &clone->size, sizeof(clone->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, clone, &clone->size,
|
||||
sizeof(clone->size));
|
||||
CHECK_BUFFER(buffer);
|
||||
CHECK_BUFFER(clone);
|
||||
|
||||
@ -739,7 +741,8 @@ merge_buffer(net_buffer *_buffer, net_buffer *_with, bool after)
|
||||
buffer->size += node->used;
|
||||
}
|
||||
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
// the data has been merged completely at this point
|
||||
free_buffer(with);
|
||||
@ -915,7 +918,8 @@ prepend_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer)
|
||||
//dprintf(" prepend_size result:\n");
|
||||
//dump_buffer(buffer);
|
||||
CHECK_BUFFER(buffer);
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@ -971,7 +975,8 @@ append_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer)
|
||||
node->tail_space = 0;
|
||||
node->used += previousTailSpace;
|
||||
buffer->size += previousTailSpace;
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
// allocate all buffers
|
||||
|
||||
@ -998,7 +1003,8 @@ append_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer)
|
||||
|
||||
buffer->size += sizeUsed;
|
||||
sizeAdded += sizeUsed;
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
list_add_item(&buffer->buffers, node);
|
||||
|
||||
@ -1025,7 +1031,8 @@ append_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer)
|
||||
|
||||
node->used += size;
|
||||
buffer->size += size;
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
//dprintf(" append result 2:\n");
|
||||
//dump_buffer(buffer);
|
||||
@ -1112,7 +1119,8 @@ remove_header(net_buffer *_buffer, size_t bytes)
|
||||
}
|
||||
|
||||
buffer->size -= bytes;
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
//dprintf(" remove result:\n");
|
||||
//dump_buffer(buffer);
|
||||
@ -1173,7 +1181,8 @@ trim_data(net_buffer *_buffer, size_t newSize)
|
||||
}
|
||||
|
||||
buffer->size = newSize;
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
//dprintf(" trim result:\n");
|
||||
//dump_buffer(buffer);
|
||||
@ -1250,7 +1259,8 @@ append_cloned_data(net_buffer *_buffer, net_buffer *_source, uint32 offset,
|
||||
//dump_buffer(buffer);
|
||||
CHECK_BUFFER(source);
|
||||
CHECK_BUFFER(buffer);
|
||||
SET_PARANOIA_CHECK(buffer, &buffer->size, sizeof(buffer->size));
|
||||
SET_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, buffer, &buffer->size,
|
||||
sizeof(buffer->size));
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -39,8 +39,7 @@
|
||||
#define TRACE_CACHE(cache, format, bananas...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define OBJECT_CACHE_PARANOIA 1
|
||||
#define ENABLE_PARANOIA_CHECK_COMPONENT OBJECT_CACHE_PARANOIA
|
||||
#define COMPONENT_PARANOIA_LEVEL OBJECT_CACHE_PARANOIA
|
||||
#include <debug_paranoia.h>
|
||||
|
||||
|
||||
@ -843,7 +842,8 @@ object_cache_alloc(object_cache *cache, uint32 flags)
|
||||
source->count--;
|
||||
cache->used_count++;
|
||||
|
||||
REMOVE_PARANOIA_CHECK(source, &link->next, sizeof(void*));
|
||||
REMOVE_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, source, &link->next,
|
||||
sizeof(void*));
|
||||
|
||||
TRACE_CACHE(cache, "allocate %p (%p) from %p, %lu remaining.",
|
||||
link_to_object(link, cache->object_size), link, source, source->count);
|
||||
@ -877,7 +877,7 @@ object_cache_return_to_slab(object_cache *cache, slab *source, void *object)
|
||||
source->count++;
|
||||
cache->used_count--;
|
||||
|
||||
ADD_PARANOIA_CHECK(source, &link->next, sizeof(void*));
|
||||
ADD_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, source, &link->next, sizeof(void*));
|
||||
|
||||
if (source->count == source->size) {
|
||||
cache->partial.Remove(source);
|
||||
@ -1000,8 +1000,8 @@ object_cache::InitSlab(slab *slab, void *pages, size_t byteCount)
|
||||
|
||||
_push(slab->free, object_to_link(data, object_size));
|
||||
|
||||
ADD_PARANOIA_CHECK(slab, &object_to_link(data, object_size)->next,
|
||||
sizeof(void*));
|
||||
ADD_PARANOIA_CHECK(PARANOIA_SUSPICIOUS, slab,
|
||||
&object_to_link(data, object_size)->next, sizeof(void*));
|
||||
|
||||
data += object_size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user