Skip to contentSkip to conversation

mktree: long is bigger on 64-bit

PATCH In review Serge E. Hallyn 2 participants 3 messages May 13, 2009 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mktree: long is bigger on 64-bit

mktree's hash function assumes that long is 32 bits. Fix.

---
 mktree.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
mktree.c +4 -2
index 7a8cecc..0195974 100644
@@ -724,6 +724,7 @@ static int ckpt_make_tree(struct ckpt_ctx *ctx, struct task *task)
 	struct task *child;
 	struct pid_swap swap;
 	pid_t newpid;
+	int status;
 	int ret;
 
 	ckpt_dbg("pid %d: pid %d sid %d parent %d\n",
@@ -765,7 +766,7 @@ static int ckpt_make_tree(struct ckpt_ctx *ctx, struct task *task)
 	/* 3rd pass: bring out your deads ... */
 	for (child = task->children; child; child = child->next_sib) {
 		if (child->flags & TASK_DEAD) {
-			ret = waitpid(child->rpid, NULL, 0);
+			ret = waitpid(child->rpid, &status, 0);
 			if (ret < 0) {
 				perror("waitpid");
 				return -1;
@@ -1291,7 +1292,8 @@ static void hash_exit(struct ckpt_ctx *ctx)
 static inline int hash_func(long key)
 {
 	unsigned long hash = key * GOLDEN_RATIO_PRIME_32;
-	return (hash >> (32 - HASH_BITS));
+	//return (hash >> (32 - HASH_BITS));
+	return (hash >> (sizeof(long)*8 - HASH_BITS));
 }
 
 static int hash_insert(struct ckpt_ctx *ctx, long key, void *data)
Signature · 1 line
1.6.1.1

A message that is not in the archive (sent off-list or not yet received): 20090513030830.GA11265-r/[email protected]

#2 lore raw
Quoted 29 lines · Serge E. Hallyn

mktree's hash function assumes that long is 32 bits. Fix.

---
 mktree.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
mktree.c +2 -1
index 7a8cecc..0195974 100644
@@ -724,6 +724,7 @@ static int ckpt_make_tree(struct ckpt_ctx *ctx, struct task *task)
 	struct task *child;
 	struct pid_swap swap;
 	pid_t newpid;
+	int status;
 	int ret;
 
 	ckpt_dbg("pid %d: pid %d sid %d parent %d\n",
@@ -765,7 +766,7 @@ static int ckpt_make_tree(struct ckpt_ctx *ctx, struct task *task)
 	/* 3rd pass: bring out your deads ... */
 	for (child = task->children; child; child = child->next_sib) {
 		if (child->flags & TASK_DEAD) {
-			ret = waitpid(child->rpid, NULL, 0);
+			ret = waitpid(child->rpid, &status, 0);
 			if (ret < 0) {
 				perror("waitpid");
 				return -1;

mktree.c static void hash_exit(struct ckpt_ctx *ctx) · line 1296

Quoted 6 lines
mktree.c +2 -1
@@ -1291,7 +1292,8 @@ static void hash_exit(struct ckpt_ctx *ctx)
 static inline int hash_func(long key)
 {
 	unsigned long hash = key * GOLDEN_RATIO_PRIME_32;
-	return (hash >> (32 - HASH_BITS));
+	//return (hash >> (32 - HASH_BITS));
+	return (hash >> (sizeof(long)*8 - HASH_BITS));

I'm guessing the // comment isn't intentional. Also, how about using sizeof(key) instead of manually inserting its type?

Cheers,
-Matt Helsley

A message that is not in the archive (sent off-list or not yet received): 20090513044853.GH3912-r/[email protected]

#4 lore raw
Quoted 31 lines · Matt Helsley
Quoted 30 lines · Serge E. Hallyn

mktree's hash function assumes that long is 32 bits. Fix.

---
 mktree.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
mktree.c +2 -1
index 7a8cecc..0195974 100644
@@ -724,6 +724,7 @@ static int ckpt_make_tree(struct ckpt_ctx *ctx, struct task *task)
 	struct task *child;
 	struct pid_swap swap;
 	pid_t newpid;
+	int status;
 	int ret;
 
 	ckpt_dbg("pid %d: pid %d sid %d parent %d\n",
@@ -765,7 +766,7 @@ static int ckpt_make_tree(struct ckpt_ctx *ctx, struct task *task)
 	/* 3rd pass: bring out your deads ... */
 	for (child = task->children; child; child = child->next_sib) {
 		if (child->flags & TASK_DEAD) {
-			ret = waitpid(child->rpid, NULL, 0);
+			ret = waitpid(child->rpid, &status, 0);
 			if (ret < 0) {
 				perror("waitpid");
 				return -1;
@@ -1291,7 +1292,8 @@ static void hash_exit(struct ckpt_ctx *ctx)
 static inline int hash_func(long key)
Quoted 8 lines

mktree.c static void hash_exit(struct ckpt_ctx *ctx) · line 1296

Quoted 5 lines
mktree.c +2 -1
 {
 	unsigned long hash = key * GOLDEN_RATIO_PRIME_32;
-	return (hash >> (32 - HASH_BITS));
+	//return (hash >> (32 - HASH_BITS));
+	return (hash >> (sizeof(long)*8 - HASH_BITS));

I'm guessing the // comment isn't intentional. Also, how about using sizeof(key) instead of manually inserting its type?

Uh, yeah, the other two hunks weren't intentional either. Crappy patch. But it still lets mktree work on 64-bit :)

-serge