1 /*
2 * Copyright (C) 2013 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 #include <cstddef>
18 #include <system/window.h>
19 #include <hardware/hardware.h>
20 #include <hardware/sensors.h>
21 #include <hardware/fb.h>
22 #include <hardware/hwcomposer.h>
23 #include <hardware/gralloc.h>
24 #include <hardware/consumerir.h>
25 #include <hardware/camera_common.h>
26 #include <hardware/camera3.h>
27
28 #define GET_PADDING(align, size) (((align) - ((size) % (align))) % (align))
29
30 #define CHECK_LAST_MEMBER(type, member) \
31 do { \
32 static constexpr size_t calc_size = offsetof(type, member) + sizeof(((type *)0)->member); \
33 static_assert(sizeof(type) == calc_size + GET_PADDING(alignof(type), calc_size), \
34 "" #member " is not the last element of " #type); \
35 } while (0)
36
CheckSizes(void)37 void CheckSizes(void) {
38 //Types defined in hardware.h
39 CHECK_LAST_MEMBER(hw_module_t, reserved);
40 CHECK_LAST_MEMBER(hw_device_t, close);
41
42 //Types defined in sensors.h
43 CHECK_LAST_MEMBER(sensors_vec_t, reserved);
44 CHECK_LAST_MEMBER(sensors_event_t, reserved1);
45 CHECK_LAST_MEMBER(struct sensor_t, reserved);
46 CHECK_LAST_MEMBER(sensors_poll_device_1_t, reserved_procs);
47
48 //Types defined in fb.h
49 CHECK_LAST_MEMBER(framebuffer_device_t, reserved_proc);
50
51 //Types defined in hwcomposer.h
52 CHECK_LAST_MEMBER(hwc_layer_1_t, reserved);
53 CHECK_LAST_MEMBER(hwc_composer_device_1_t, reserved_proc);
54
55 //Types defined in gralloc.h
56 CHECK_LAST_MEMBER(gralloc_module_t, reserved_proc);
57 CHECK_LAST_MEMBER(alloc_device_t, reserved_proc);
58
59 //Types defined in consumerir.h
60 CHECK_LAST_MEMBER(consumerir_device_t, reserved);
61
62 //Types defined in camera_common.h
63 CHECK_LAST_MEMBER(vendor_tag_ops_t, reserved);
64 CHECK_LAST_MEMBER(camera_module_t, reserved);
65
66 //Types defined in camera3.h
67 CHECK_LAST_MEMBER(camera3_device_ops_t, reserved);
68 }
69
70