diff options
author | Jiyong Park | 2017-09-03 20:55:09 -0500 |
---|---|---|
committer | Jiyong Park | 2017-09-06 01:30:50 -0500 |
commit | 98c0d030c9a1ca7a94ebfe1d8db167973be504d3 (patch) | |
tree | 8c02ea3e0608ad1a3f7ec5b47ebd5a77bc746cfb /liblog | |
parent | e6474b7fa23f2d00c2aa9ea9162231790d9d8a2b (diff) | |
download | platform-system-core-98c0d030c9a1ca7a94ebfe1d8db167973be504d3.tar.gz platform-system-core-98c0d030c9a1ca7a94ebfe1d8db167973be504d3.tar.xz platform-system-core-98c0d030c9a1ca7a94ebfe1d8db167973be504d3.zip |
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
Diffstat (limited to 'liblog')
-rw-r--r-- | liblog/include/log/log_time.h | 10 | ||||
-rw-r--r--[l---------] | liblog/include_vndk/log/log_time.h | 48 |
2 files changed, 54 insertions, 4 deletions
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 @@ | |||
28 | #ifndef __struct_log_time_defined | 28 | #ifndef __struct_log_time_defined |
29 | #define __struct_log_time_defined | 29 | #define __struct_log_time_defined |
30 | 30 | ||
31 | #define LOG_TIME_SEC(t) ((t)->tv_sec) | ||
32 | /* next power of two after NS_PER_SEC */ | ||
33 | #define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2)) | ||
34 | |||
31 | #ifdef __cplusplus | 35 | #ifdef __cplusplus |
32 | 36 | ||
33 | /* | 37 | /* |
@@ -167,15 +171,15 @@ struct log_time { | |||
167 | #endif | 171 | #endif |
168 | } __attribute__((__packed__)); | 172 | } __attribute__((__packed__)); |
169 | 173 | ||
170 | #else | 174 | #else /* __cplusplus */ |
171 | 175 | ||
172 | typedef struct log_time { | 176 | typedef struct log_time { |
173 | uint32_t tv_sec; | 177 | uint32_t tv_sec; |
174 | uint32_t tv_nsec; | 178 | uint32_t tv_nsec; |
175 | } __attribute__((__packed__)) log_time; | 179 | } __attribute__((__packed__)) log_time; |
176 | 180 | ||
177 | #endif | 181 | #endif /* __cplusplus */ |
178 | 182 | ||
179 | #endif | 183 | #endif /* __struct_log_time_defined */ |
180 | 184 | ||
181 | #endif /* _LIBS_LOG_LOG_TIME_H */ | 185 | #endif /* _LIBS_LOG_LOG_TIME_H */ |
diff --git a/liblog/include_vndk/log/log_time.h b/liblog/include_vndk/log/log_time.h index abfe439ae..5a09959a7 120000..100644 --- a/liblog/include_vndk/log/log_time.h +++ b/liblog/include_vndk/log/log_time.h | |||
@@ -1 +1,47 @@ | |||
1 | ../../include/log/log_time.h \ No newline at end of file | 1 | /* |
2 | * Copyright (C) 2005-2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef _LIBS_LOG_LOG_TIME_H | ||
18 | #define _LIBS_LOG_LOG_TIME_H | ||
19 | |||
20 | #include <stdint.h> | ||
21 | |||
22 | /* struct log_time is a wire-format variant of struct timespec */ | ||
23 | #ifndef NS_PER_SEC | ||
24 | #define NS_PER_SEC 1000000000ULL | ||
25 | #endif | ||
26 | #ifndef US_PER_SEC | ||
27 | #define US_PER_SEC 1000000ULL | ||
28 | #endif | ||
29 | #ifndef MS_PER_SEC | ||
30 | #define MS_PER_SEC 1000ULL | ||
31 | #endif | ||
32 | |||
33 | #ifndef __struct_log_time_defined | ||
34 | #define __struct_log_time_defined | ||
35 | |||
36 | #define LOG_TIME_SEC(t) ((t)->tv_sec) | ||
37 | /* next power of two after NS_PER_SEC */ | ||
38 | #define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2)) | ||
39 | |||
40 | typedef struct log_time { | ||
41 | uint32_t tv_sec; | ||
42 | uint32_t tv_nsec; | ||
43 | } __attribute__((__packed__)) log_time; | ||
44 | |||
45 | #endif | ||
46 | |||
47 | #endif /* _LIBS_LOG_LOG_TIME_H */ | ||