summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2017-04-21 03:10:56 (GMT)
committerElliott Sales de Andrade <quantum.analyst@gmail.com>2017-09-16 07:54:11 (GMT)
commitbf4fb03e4b266e7f75f88664b6a941d20650046b (patch)
tree1b1e26f0359d561cdf9b05469550b84a91a223a8
parenteb6cea27f23c0674cea47871f281aaffb8a8efc3 (diff)
downloadNinja-bf4fb03e4b266e7f75f88664b6a941d20650046b.zip
Ninja-bf4fb03e4b266e7f75f88664b6a941d20650046b.tar.gz
Ninja-bf4fb03e4b266e7f75f88664b6a941d20650046b.tar.bz2
Use 64-bit-alignment-safe timestamp reading.
Read and write the timestamp as two separate 32-bit integers in a fixed order to prevent any issues with alignment or byte order.
-rw-r--r--src/deps_log.cc10
-rw-r--r--src/deps_log.h5
2 files changed, 11 insertions, 4 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc
index d7f0b26..4239426 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -135,7 +135,11 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
int id = node->id();
if (fwrite(&id, 4, 1, file_) < 1)
return false;
- if (fwrite(&mtime, 8, 1, file_) < 1)
+ uint32_t mtime_part = static_cast<uint32_t>(mtime & 0xffffffff);
+ if (fwrite(&mtime_part, 4, 1, file_) < 1)
+ return false;
+ mtime_part = static_cast<uint32_t>((mtime >> 32) & 0xffffffff);
+ if (fwrite(&mtime_part, 4, 1, file_) < 1)
return false;
for (int i = 0; i < node_count; ++i) {
id = nodes[i]->id();
@@ -217,7 +221,9 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
assert(size % 4 == 0);
int* deps_data = reinterpret_cast<int*>(buf);
int out_id = deps_data[0];
- TimeStamp mtime = reinterpret_cast<TimeStamp*>(&deps_data[1])[0];
+ TimeStamp mtime;
+ mtime = (TimeStamp)(((uint64_t)(unsigned int)deps_data[2] << 32) |
+ (uint64_t)(unsigned int)deps_data[1]);
deps_data += 3;
int deps_count = (size / 4) - 3;
diff --git a/src/deps_log.h b/src/deps_log.h
index 793af07..b1aa361 100644
--- a/src/deps_log.h
+++ b/src/deps_log.h
@@ -57,8 +57,9 @@ struct State;
/// one's complement of the expected index of the record (to detect
/// concurrent writes of multiple ninja processes to the log).
/// dependency records are an array of 4-byte integers
-/// [output path id, output path mtime (8-byte int), input path id,
-/// input path id...]
+/// [output path id,
+/// output path mtime (lower 4 bytes), output path mtime (upper 8 bytes),
+/// input path id, input path id...]
/// (The mtime is compared against the on-disk output path mtime
/// to verify the stored data is up-to-date.)
/// If two records reference the same output the latter one in the file