From e6474b7fa23f2d00c2aa9ea9162231790d9d8a2b Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 6 Sep 2017 12:21:40 +0900 Subject: [PATCH 1/2] Don't rely on transitively included headers One must explicitly include what it need. time.h for clock_gettime Bug: 37629934 Test: build Merged-In: I992eac637f373b204aa161b0b26f5563e952c27e Change-Id: I992eac637f373b204aa161b0b26f5563e952c27e --- libutils/SystemClock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp index 28fc35145..73ec1be96 100644 --- a/libutils/SystemClock.cpp +++ b/libutils/SystemClock.cpp @@ -23,9 +23,9 @@ #include -#include #include #include +#include #include From 98c0d030c9a1ca7a94ebfe1d8db167973be504d3 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 4 Sep 2017 10:55:09 +0900 Subject: [PATCH 2/2] Hide implementation details of log_time struct In the future, the sizes of tv_sec and tv_nsec (or even the size of log_time struct itself) can change due to the 32-bit overflow expected to happen in the year 2138. In order to hide such implementation details to the clients of liblog, the two macros LOG_TIME_SEC and LOG_TIME_NSEC are introduced. Furthermore, vendors are provided with a simplified version of log_time.h without C++ APIs. In doing so, log_time.h no longer includes time.h. This breaks several modules that implicitly relied on the hidden dependency, which should be fixed. Bug: 37629934 Test: build with BOARD_VNDK_VERSION=current Change-Id: I01b36078c1d8f3f44824be20ae769ba1465b6feb --- liblog/include/log/log_time.h | 10 +++++-- liblog/include_vndk/log/log_time.h | 48 +++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) mode change 120000 => 100644 liblog/include_vndk/log/log_time.h diff --git a/liblog/include/log/log_time.h b/liblog/include/log/log_time.h index 3764faf75..309f5d12f 100644 --- a/liblog/include/log/log_time.h +++ b/liblog/include/log/log_time.h @@ -28,6 +28,10 @@ #ifndef __struct_log_time_defined #define __struct_log_time_defined +#define LOG_TIME_SEC(t) ((t)->tv_sec) +/* next power of two after NS_PER_SEC */ +#define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2)) + #ifdef __cplusplus /* @@ -167,15 +171,15 @@ struct log_time { #endif } __attribute__((__packed__)); -#else +#else /* __cplusplus */ typedef struct log_time { uint32_t tv_sec; uint32_t tv_nsec; } __attribute__((__packed__)) log_time; -#endif +#endif /* __cplusplus */ -#endif +#endif /* __struct_log_time_defined */ #endif /* _LIBS_LOG_LOG_TIME_H */ diff --git a/liblog/include_vndk/log/log_time.h b/liblog/include_vndk/log/log_time.h deleted file mode 120000 index abfe439ae..000000000 --- a/liblog/include_vndk/log/log_time.h +++ /dev/null @@ -1 +0,0 @@ -../../include/log/log_time.h \ No newline at end of file diff --git a/liblog/include_vndk/log/log_time.h b/liblog/include_vndk/log/log_time.h new file mode 100644 index 000000000..5a09959a7 --- /dev/null +++ b/liblog/include_vndk/log/log_time.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2005-2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _LIBS_LOG_LOG_TIME_H +#define _LIBS_LOG_LOG_TIME_H + +#include + +/* struct log_time is a wire-format variant of struct timespec */ +#ifndef NS_PER_SEC +#define NS_PER_SEC 1000000000ULL +#endif +#ifndef US_PER_SEC +#define US_PER_SEC 1000000ULL +#endif +#ifndef MS_PER_SEC +#define MS_PER_SEC 1000ULL +#endif + +#ifndef __struct_log_time_defined +#define __struct_log_time_defined + +#define LOG_TIME_SEC(t) ((t)->tv_sec) +/* next power of two after NS_PER_SEC */ +#define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2)) + +typedef struct log_time { + uint32_t tv_sec; + uint32_t tv_nsec; +} __attribute__((__packed__)) log_time; + +#endif + +#endif /* _LIBS_LOG_LOG_TIME_H */