Fix compiler errors when using libc++ in verity.

Rename macros min,max and to_bytes.
min and max macros are no longer allowed in c++.
to_bytes conflict with a header function in <locale>.

Fixes compilation errors:
/build/caroline/usr/include/c++/v1/locale:3596:48: error: too many arguments
verity-9999:       provided to function-like macro invocation
verity-9999:     byte_string to_bytes(const _Elem* __first, const _Elem* __last);
verity-9999: /mnt/host/source/src/platform/verity/include/linux/device-mapper.h:31:9: note:
verity-9999:       macro 'to_bytes' defined here
verity-9999: #define to_bytes(x) ((x) << SECTOR_SHIFT)

verity-9999: /build/caroline/usr/include/c++/v1/__undef_min_max:17:2: error: macro min is
verity-9999:       incompatible with C++. #undefing min [-Werror,-W#warnings]
verity-9999: #warning: macro min is incompatible with C++.  #undefing min
verity-9999: /build/caroline/usr/include/c++/v1/__undef_min_max:29:2: error: macro max is
verity-9999:       incompatible with C++. #undefing max [-Werror,-W#warnings]
verity-9999: #warning: macro max is incompatible with C++.  #undefing max

BUG=chromium:724628
TEST=verity compiles.

Change-Id: I709edbe48085c3dd692037957f9139010e9e5844
Reviewed-on: https://chromium-review.googlesource.com/547454
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
diff --git a/dm-bht.c b/dm-bht.c
index ccc7a17..c190b69 100644
--- a/dm-bht.c
+++ b/dm-bht.c
@@ -286,7 +286,7 @@
 	 * on allocation or sector calculation.
 	 */
 	if (((last_index >> bht->node_count_shift) + 1) >
-	    UINT_MAX / max((unsigned int)sizeof(struct dm_bht_entry),
+	    UINT_MAX / MAX((unsigned int)sizeof(struct dm_bht_entry),
 			   (unsigned int)to_sector(PAGE_SIZE))) {
 		DMCRIT("required entries %u is too large",
 		       last_index + 1);
@@ -438,7 +438,7 @@
 int dm_bht_zeroread_callback(void *ctx, sector_t start, u8 *dst,
 			     sector_t count, struct dm_bht_entry *entry)
 {
-	memset(dst, 0, to_bytes(count));
+	memset(dst, 0, verity_to_bytes(count));
 	dm_bht_read_completed(entry, 0);
 	return 0;
 }
@@ -671,7 +671,7 @@
  */
 void dm_bht_set_salt(struct dm_bht *bht, const char *hexsalt)
 {
-	size_t saltlen = min(strlen(hexsalt) / 2, sizeof(bht->salt));
+	size_t saltlen = MIN(strlen(hexsalt) / 2, sizeof(bht->salt));
 	bht->have_salt = true;
 	memset(bht->salt, 0, sizeof(bht->salt));
 	dm_bht_hex_to_bin(bht->salt, (const u8 *)hexsalt, saltlen);
diff --git a/dm-bht_unittest.cc b/dm-bht_unittest.cc
index 2eadf84..ae82bf4 100644
--- a/dm-bht_unittest.cc
+++ b/dm-bht_unittest.cc
@@ -54,7 +54,7 @@
   EXPECT_EQ(0, dm_bht_create(&bht, blocks, "sha256"));
   dm_bht_set_read_cb(&bht, dm_bht_zeroread_callback);
   sectors = dm_bht_sectors(&bht);
-  hash_data = new u8[to_bytes(sectors)];
+  hash_data = new u8[verity_to_bytes(sectors)];
   dm_bht_set_buffer(&bht, hash_data);
 
   do {
@@ -87,9 +87,9 @@
 
   int Read(sector_t start, u8 *dst, sector_t count) {
     EXPECT_LT(start, sectors_);
-    EXPECT_EQ(to_bytes(count), PAGE_SIZE);
-    u8 *src = &hash_data_[to_bytes(start)];
-    memcpy(dst, src, to_bytes(count));
+    EXPECT_EQ(verity_to_bytes(count), PAGE_SIZE);
+    u8 *src = &hash_data_[verity_to_bytes(start)];
+    memcpy(dst, src, verity_to_bytes(count));
     return 0;
   }
 
@@ -142,7 +142,7 @@
 
     EXPECT_EQ(0, dm_bht_create(bht_, total_blocks, digest_algorithm));
     sectors_ = dm_bht_sectors(bht_);
-    hash_data_.resize(to_bytes(sectors_));
+    hash_data_.resize(verity_to_bytes(sectors_));
 
     if (salt)
       dm_bht_set_salt(bht_, salt);
diff --git a/file_hasher.cc b/file_hasher.cc
index d98186e..1066965 100644
--- a/file_hasher.cc
+++ b/file_hasher.cc
@@ -63,7 +63,7 @@
   }
 
   sectors_ = dm_bht_sectors(&tree_);
-  hash_data_ = new u8[to_bytes(sectors_)];
+  hash_data_ = new u8[verity_to_bytes(sectors_)];
 
   // No reading is needed.
   dm_bht_set_read_cb(&tree_, dm_bht_zeroread_callback);
@@ -72,7 +72,7 @@
 }
 
 bool FileHasher::Store() {
-  return destination_->WriteAt(to_bytes(sectors_), hash_data_, 0);
+  return destination_->WriteAt(verity_to_bytes(sectors_), hash_data_, 0);
 }
 
 bool FileHasher::Hash() {
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index db2b90b..0d22467 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -28,6 +28,6 @@
 
 #define SECTOR_SHIFT 9
 #define to_sector(x) ((x) >> SECTOR_SHIFT)
-#define to_bytes(x) ((x) << SECTOR_SHIFT)
+#define verity_to_bytes(x) ((x) << SECTOR_SHIFT)
 
 #endif  /* VERITY_INCLUDE_LINUX_DEVICE_MAPPER_H_ */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 16deee3..ca0893d 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -24,13 +24,13 @@
 	_res; \
 })
 
-#define min(x, y) ({				\
+#define MIN(x, y) ({				\
 	typeof(x) _min1 = (x);			\
 	typeof(y) _min2 = (y);			\
 	(void) (&_min1 == &_min2);		\
 	_min1 < _min2 ? _min1 : _min2; })
 
-#define max(x, y) ({				\
+#define MAX(x, y) ({				\
 	typeof(x) _max1 = (x);			\
 	typeof(y) _max2 = (y);			\
 	(void) (&_max1 == &_max2);		\