system/core
修订版 | f4212744edd3edf9ba55668c3e4755f1e3a3e897 (tree) |
---|---|
时间 | 2019-04-03 09:34:36 |
作者 | Yifan Hong <elsk@goog...> |
Commiter | Yifan Hong |
libprocessgroup: Add libcgrouprc_format
This module defines the wire format of the mmap()ed cgroup.rc
file.
Test: builds
Bug: 123664216
Change-Id: Iaf6199f759a6264590b13ca7ba6d7f576c3ed56a
@@ -0,0 +1,32 @@ | ||
1 | +// Copyright (C) 2019 The Android Open Source Project | |
2 | +// | |
3 | +// Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | +// you may not use this file except in compliance with the License. | |
5 | +// You may obtain a copy of the License at | |
6 | +// | |
7 | +// http://www.apache.org/licenses/LICENSE-2.0 | |
8 | +// | |
9 | +// Unless required by applicable law or agreed to in writing, software | |
10 | +// distributed under the License is distributed on an "AS IS" BASIS, | |
11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | +// See the License for the specific language governing permissions and | |
13 | +// limitations under the License. | |
14 | + | |
15 | +cc_library_static { | |
16 | + name: "libcgrouprc_format", | |
17 | + host_supported: true, | |
18 | + recovery_available: true, | |
19 | + srcs: [ | |
20 | + "cgroup_controller.cpp", | |
21 | + ], | |
22 | + cflags: [ | |
23 | + "-Wall", | |
24 | + "-Werror", | |
25 | + ], | |
26 | + export_include_dirs: [ | |
27 | + "include", | |
28 | + ], | |
29 | + shared_libs: [ | |
30 | + "libbase", | |
31 | + ], | |
32 | +} |
@@ -0,0 +1,49 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2019 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 <processgroup/format/cgroup_controller.h> | |
18 | + | |
19 | +namespace android { | |
20 | +namespace cgrouprc { | |
21 | +namespace format { | |
22 | + | |
23 | +CgroupController::CgroupController(uint32_t version, const std::string& name, | |
24 | + const std::string& path) { | |
25 | + // strlcpy isn't available on host. Although there is an implementation | |
26 | + // in licutils, libcutils itself depends on libcgrouprc_format, causing | |
27 | + // a circular dependency. | |
28 | + version_ = version; | |
29 | + strncpy(name_, name.c_str(), sizeof(name_) - 1); | |
30 | + name_[sizeof(name_) - 1] = '\0'; | |
31 | + strncpy(path_, path.c_str(), sizeof(path_) - 1); | |
32 | + path_[sizeof(path_) - 1] = '\0'; | |
33 | +} | |
34 | + | |
35 | +uint32_t CgroupController::version() const { | |
36 | + return version_; | |
37 | +} | |
38 | + | |
39 | +const char* CgroupController::name() const { | |
40 | + return name_; | |
41 | +} | |
42 | + | |
43 | +const char* CgroupController::path() const { | |
44 | + return path_; | |
45 | +} | |
46 | + | |
47 | +} // namespace format | |
48 | +} // namespace cgrouprc | |
49 | +} // namespace android |
@@ -0,0 +1,47 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2019 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 | +#pragma once | |
18 | + | |
19 | +#include <stdint.h> | |
20 | +#include <string> | |
21 | + | |
22 | +namespace android { | |
23 | +namespace cgrouprc { | |
24 | +namespace format { | |
25 | + | |
26 | +// Minimal controller description to be mmapped into process address space | |
27 | +struct CgroupController { | |
28 | + public: | |
29 | + CgroupController() {} | |
30 | + CgroupController(uint32_t version, const std::string& name, const std::string& path); | |
31 | + | |
32 | + uint32_t version() const; | |
33 | + const char* name() const; | |
34 | + const char* path() const; | |
35 | + | |
36 | + private: | |
37 | + static constexpr size_t CGROUP_NAME_BUF_SZ = 16; | |
38 | + static constexpr size_t CGROUP_PATH_BUF_SZ = 32; | |
39 | + | |
40 | + uint32_t version_; | |
41 | + char name_[CGROUP_NAME_BUF_SZ]; | |
42 | + char path_[CGROUP_PATH_BUF_SZ]; | |
43 | +}; | |
44 | + | |
45 | +} // namespace format | |
46 | +} // namespace cgrouprc | |
47 | +} // namespace android |
@@ -0,0 +1,36 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2019 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 | +#pragma once | |
18 | + | |
19 | +#include <processgroup/format/cgroup_controller.h> | |
20 | + | |
21 | +namespace android { | |
22 | +namespace cgrouprc { | |
23 | +namespace format { | |
24 | + | |
25 | +struct CgroupFile { | |
26 | + uint32_t version_; | |
27 | + uint32_t controller_count_; | |
28 | + CgroupController controllers_[]; | |
29 | + | |
30 | + static constexpr uint32_t FILE_VERSION_1 = 1; | |
31 | + static constexpr uint32_t FILE_CURR_VERSION = FILE_VERSION_1; | |
32 | +}; | |
33 | + | |
34 | +} // namespace format | |
35 | +} // namespace cgrouprc | |
36 | +} // namespace android |