Permalink
Browse files

Changes to W32 pipe/process handling, trying to get it working.

Fixed broken remote testing.
Added dump of allocator tree if allocator OOMs.
  • Loading branch information...
1 parent 16719cd commit 6ad4812d9adf54ce9dec4ce39804e4159afef84c Caleb James DeLisle committed Dec 12, 2012
View
@@ -203,7 +203,8 @@ add_definitions("-D CJDNS_MAX_PEERS=${CJDNS_MAX_PEERS}")
# make sure casts are done properly.
add_definitions("-D Identity_CHECK=1")
-
+# add in a billion checks which slow things down but catch bugs.
+add_definitions("-D PARANOIA=1")
include_directories(${CMAKE_SOURCE_DIR})
View
@@ -123,7 +123,7 @@ static void freeChannel(void* vchannel)
static void newChannel(struct Channel** location, struct Allocator* alloc)
{
- struct Allocator* childAlloc = alloc->child(alloc);
+ struct Allocator* childAlloc = Allocator_child(alloc);
struct Channel* out = childAlloc->clone(sizeof(struct Channel), alloc, &(struct Channel) {
.alloc = childAlloc
});
@@ -396,7 +396,7 @@ static void handleMessage(struct Message* message,
// Try to handle multiple stacked requests in the same frame.
for (;;) {
- struct Allocator* allocator = admin->allocator->child(admin->allocator);
+ struct Allocator* allocator = Allocator_child(admin->allocator);
struct Reader* reader = ArrayReader_new(message->bytes, message->length, allocator);
char nextByte;
View
@@ -212,7 +212,7 @@ static void subscribe(Dict* args, void* vcontext, String* txid)
} else {
struct Subscription* sub = &log->subscriptions[log->subscriptionCount];
sub->level = level;
- sub->alloc = log->alloc->child(log->alloc);
+ sub->alloc = Allocator_child(log->alloc);
if (file) {
int i;
for (i = 0; i < FILE_NAME_COUNT; i++) {
View
@@ -110,7 +110,7 @@ static void authorizedPasswords(List* list, struct Context* ctx)
String_CONST("authType"), Int_OBJ(1), Dict_CONST(
String_CONST("password"), String_OBJ(passwd), NULL
));
- struct Allocator* child = ctx->alloc->child(ctx->alloc);
+ struct Allocator* child = Allocator_child(ctx->alloc);
rpcCall(String_CONST("AuthorizedPasswords_add"), &args, ctx, child);
child->free(child);
}
@@ -153,7 +153,7 @@ static void udpInterface(Dict* config, struct Context* ctx)
Log_keys(ctx->logger, "Attempting to connect to node [%s].", key->bytes);
- struct Allocator* perCallAlloc = ctx->alloc->child(ctx->alloc);
+ struct Allocator* perCallAlloc = Allocator_child(ctx->alloc);
Dict_putString(value, String_CONST("address"), key, perCallAlloc);
rpcCall(String_CONST("UDPInterface_beginConnection"), value, ctx, perCallAlloc);
perCallAlloc->free(perCallAlloc);
@@ -258,7 +258,7 @@ static void ethInterface(Dict* config, struct Context* ctx)
Log_keys(ctx->logger, "Attempting to connect to node [%s].", key->bytes);
- struct Allocator* perCallAlloc = ctx->alloc->child(ctx->alloc);
+ struct Allocator* perCallAlloc = Allocator_child(ctx->alloc);
Dict_putString(value, String_CONST("macAddress"), key, perCallAlloc);
rpcCall(String_CONST("ETHInterface_beginConnection"), value, ctx, perCallAlloc);
perCallAlloc->free(perCallAlloc);
@@ -300,7 +300,7 @@ void Configurator_config(Dict* config,
struct Log* logger,
struct Allocator* alloc)
{
- struct Allocator* tempAlloc = alloc->child(alloc);
+ struct Allocator* tempAlloc = Allocator_child(alloc);
struct AdminClient* client =
AdminClient_new(sockAddr, addrLen, adminPassword, eventBase, logger, tempAlloc);
View
@@ -327,7 +327,7 @@ int AngelInit_main(int argc, char** argv)
sendConfToCore(coreIface, alloc, &config, eh, logger);
- struct Allocator* tempAlloc = alloc->child(alloc);
+ struct Allocator* tempAlloc = Allocator_child(alloc);
InterfaceWaiter_waitForData(coreIface, eventBase, tempAlloc, eh);
tempAlloc->free(tempAlloc);
View
@@ -101,7 +101,7 @@ static bool fileExists(const char* filename)
static String* getCorePath(struct Allocator* alloc)
{
- struct Allocator* alloc2 = alloc->child(alloc);
+ struct Allocator* alloc2 = Allocator_child(alloc);
char* cjdroute2Path = Process_getPath(alloc2);
char* lastSlash = strrchr(cjdroute2Path, '/');
Assert_always(lastSlash != NULL);
@@ -431,13 +431,13 @@ int main(int argc, char** argv)
if (!corePath) {
corePath = getCorePath(allocator);
- }
- if (!corePath) {
- Except_raise(eh, -1, "Can't find a usable cjdns core executable, "
- "try specifying the location in your cjdroute.conf");
- } else {
- Log_warn(logger, "Cjdns core executable was not specified in cjdroute.conf, "
- "guessing its location.");
+ if (!corePath) {
+ Except_raise(eh, -1, "Can't find a usable cjdns core executable, "
+ "try specifying the location in your cjdroute.conf");
+ } else {
+ Log_warn(logger, "Cjdns core executable was not specified in cjdroute.conf, "
+ "guessing its location.");
+ }
}
if (!privateKey) {
@@ -108,7 +108,7 @@ static inline int parseString(const struct Reader* reader,
#define BUFF_MAX (1<<20)
int curSize = BUFF_SZ;
- struct Allocator* localAllocator = allocator->child(allocator);
+ struct Allocator* localAllocator = Allocator_child(allocator);
uint8_t* buffer = localAllocator->malloc(curSize, localAllocator);
if (readUntil('"', reader) || reader->read(buffer, 1, reader)) {
printf("Unterminated string\n");
@@ -11,11 +11,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
let line=0
-curl --data-binary @__TEST_FILE__ __REMOTE_TEST_IP_PORT__ 2>>/dev/null \
-| while read x
+for x in `curl --data-binary @__TEST_FILE__ __REMOTE_TEST_IP_PORT__ 2>>/dev/null`
do
- [ "${line}" == "0" ] && echo "$x" | grep '4:codei0e' >/dev/null && exit 1;
+ [ "${line}" == "0" ] && echo "$x" | grep '4:codei0e' >/dev/null && echo 'Passed' && exit 0;
+ echo 'Failed'
echo "$x";
let "line = line + 1"
-done || exit 0;
-exit 1;
+done && exit 1;
+
@@ -1137,7 +1137,7 @@ int RouterModule_pingNode(struct Node* node,
Log_debug(module->logger, "Ping %s\n", addr);
#endif
- struct Allocator* pingAllocator = module->allocator->child(module->allocator);
+ struct Allocator* pingAllocator = Allocator_child(module->allocator);
struct RouterModule_Ping* ping =
pingAllocator->calloc(sizeof(struct RouterModule_Ping), 1, pingAllocator);
*location = ping;
@@ -115,7 +115,7 @@ struct SearchStore_Search* SearchStore_newSearch(
return NULL;
}
- struct Allocator* allocator = store->allocator->child(store->allocator);
+ struct Allocator* allocator = Allocator_child(store->allocator);
struct SearchStore_Search* search =
allocator->calloc(sizeof(struct SearchStore_Search), 1, allocator);
search->searchIndex = i;
@@ -89,7 +89,7 @@ static void newInterface(Dict* args, void* vcontext, String* txid)
{
struct Context* const ctx = vcontext;
String* const bindDevice = Dict_getString(args, String_CONST("bindDevice"));
- struct Allocator* const alloc = ctx->allocator->child(ctx->allocator);
+ struct Allocator* const alloc = Allocator_child(ctx->allocator);
struct ETHInterface* ethIf = NULL;
struct Jmp jmp;
@@ -89,7 +89,7 @@ struct SessionManager_Session* SessionManager_getSession(uint8_t* lookupKey,
// Make sure cleanup() doesn't get behind.
cleanup(sm);
- struct Allocator* ifAllocator = sm->allocator->child(sm->allocator);
+ struct Allocator* ifAllocator = Allocator_child(sm->allocator);
struct Interface* outsideIf =
ifAllocator->clone(sizeof(struct Interface), ifAllocator, &(struct Interface) {
.sendMessage = sm->encryptedOutgoing,
@@ -88,7 +88,7 @@ static void newInterface(Dict* args, void* vcontext, String* txid)
{
struct Context* const ctx = vcontext;
String* const bindAddress = Dict_getString(args, String_CONST("bindAddress"));
- struct Allocator* const alloc = ctx->allocator->child(ctx->allocator);
+ struct Allocator* const alloc = Allocator_child(ctx->allocator);
struct UDPInterface* udpIf = NULL;
struct Jmp jmp;
View
@@ -123,10 +123,14 @@ struct Allocator
* Get a new child of this allocator.
* When this allocator is freed all of its children will be freed as well.
*
- * @param this the memory allocator, use allocator->child(allocator) to get a child.
+ * @param this the memory allocator, use Allocator_child(allocator) to get a child.
+ * @param identFile the name of the file where this was called from to aid in debugging.
+ * @param identLine the line number where this was called.
* @return a child allocator.
*/
- struct Allocator* (* const child)(const struct Allocator* this);
+ struct Allocator* (* const child)(const struct Allocator* thisAlloc,
+ const char* identFile,
+ int identLine);
};
#define Allocator_clone(alloc, content) \
@@ -148,7 +152,7 @@ struct Allocator
alloc->realloc(orig, size, alloc)
#define Allocator_child(alloc) \
- alloc->child(alloc)
+ alloc->child(alloc, __FILE__, __LINE__)
#define Allocator_free(alloc) \
alloc->free(alloc)
View
@@ -186,8 +186,10 @@ static bool removeOnFreeJob(void* toRemove, struct Allocator* alloc)
return false;
}
-/** @see Allocator->child() */
-static struct Allocator* childAllocator(const struct Allocator* allocator)
+/** @see Allocator_child() */
+static struct Allocator* childAllocator(const struct Allocator* allocator,
+ const char* identFile,
+ int identLine)
{
return allocator->clone(sizeof(struct Allocator), allocator, &(struct Allocator) {
.context = allocator->context,
View
@@ -22,7 +22,7 @@
* Create a new Allocator which allocates from to a user supplied buffer.
* This allocator will reset the pointer to the beginning of the buffer when
* free() is called on it, it is up to the user to free their buffer.
- * allocator->child(allocator) always returns NULL.
+ * Allocator_child(allocator) always returns NULL.
*
* @param buffer an array to write to.
* @param length the size of the array. If more is written than this length,
View
@@ -91,6 +91,21 @@ static void* allocatorClone(size_t length, const struct Allocator* allocator, co
return pointer;
}
+/** @see Allocator->onFree() */
+static void* addOnFreeJob(void (* callback)(void* callbackContext),
+ void* callbackContext,
+ const struct Allocator* allocator)
+{
+ struct CanaryAllocator_pvt* ctx = Identity_cast((struct CanaryAllocator_pvt*) allocator);
+ return ctx->alloc->onFree(callback, callbackContext, ctx->alloc);
+}
+
+static bool removeOnFreeJob(void* toRemove, struct Allocator* alloc)
+{
+ struct CanaryAllocator_pvt* ctx = Identity_cast((struct CanaryAllocator_pvt*) alloc);
+ return ctx->alloc->notOnFree(toRemove, ctx->alloc);
+}
+
/** @see Allocator->realloc() */
static void* allocatorRealloc(const void* original,
size_t size,
@@ -116,11 +131,13 @@ static void* allocatorRealloc(const void* original,
return newAllocation(ctx, out, SIZE_INTS(size));
}
-/** @see Allocator->child() */
-static struct Allocator* childAllocator(const struct Allocator* allocator)
+/** @see Allocator_child() */
+static struct Allocator* childAllocator(const struct Allocator* allocator,
+ const char* identFile,
+ int identLine)
{
struct CanaryAllocator_pvt* ctx = Identity_cast((struct CanaryAllocator_pvt*) allocator);
- return CanaryAllocator_new(ctx->alloc->child(ctx->alloc), ctx->rand);
+ return CanaryAllocator_new(ctx->alloc->child(ctx->alloc, identFile, identLine), ctx->rand);
}
/** @see MallocAllocator.h */
@@ -134,8 +151,8 @@ struct Allocator* CanaryAllocator_new(struct Allocator* alloc, struct Random* ra
.clone = allocatorClone,
.realloc = allocatorRealloc,
.child = childAllocator,
- .onFree = alloc->onFree,
- .notOnFree = alloc->notOnFree,
+ .onFree = addOnFreeJob,
+ .notOnFree = removeOnFreeJob,
.context = alloc->context
},
.alloc = alloc,
Oops, something went wrong.

0 comments on commit 6ad4812

Please sign in to comment.