From e90ddd3c4222e68051fadea3d76426881af900fb Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Fri, 11 Jun 2021 12:39:29 +0200 Subject: [PATCH 01/16] telf: Fix uninitialized pointer read Change-Id: I8bf8dbed9af82c895ec3040eeafdb03a0d74fd04 --- src/crash-stack/unwind.c | 4 ++++ src/shared/telf.c | 1 + 2 files changed, 5 insertions(+) diff --git a/src/crash-stack/unwind.c b/src/crash-stack/unwind.c index 44bff5d..3a2b455 100644 --- a/src/crash-stack/unwind.c +++ b/src/crash-stack/unwind.c @@ -79,6 +79,10 @@ static FILE *debug; static Elf *elf_start(int fd, char *image, uint64_t size) { Elf *elf = malloc(sizeof(Elf)); + if (elf == NULL) { + _E("Out of memory"); + return NULL; + } if (fd > 0) { if (!teu_begin(fd, elf)) diff --git a/src/shared/telf.c b/src/shared/telf.c index 09508c1..87b5209 100644 --- a/src/shared/telf.c +++ b/src/shared/telf.c @@ -174,6 +174,7 @@ bool teu_begin_memory(void *memory, Elf *elf) assert(elf); elf->status = TEU_MEMORY; + elf->data = memory; if (!teu_init(elf)) return false; -- 2.7.4 From e3d53e934e15a6922402b0e60e1189e47805aa64 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Fri, 11 Jun 2021 13:23:35 +0200 Subject: [PATCH 02/16] Release 6.5.21 Change-Id: I8d58aab1e533cb1563d9f053df79a73ea72e8963 --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index c6d33c1..432bda1 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -16,7 +16,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 6.5.20 +Version: 6.5.21 Release: 1 Group: Framework/system License: Apache-2.0 and BSD-2-Clause and MIT -- 2.7.4 From a9868fda7cd7166ed4cc66c17c0535ca6ea0daf1 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Fri, 19 Feb 2021 11:41:07 +0100 Subject: [PATCH 03/16] system-tests: Fix behavior when dump directory is missing Since crash-manager is responsible for creating dump directory (commit 96a11f21e013e1de3d02ee438c4291d55de56e9e), the absence of this directory cannot be considered as an error. Change-Id: I8db05869c951b3d9b893a223d020dc146ba9455f --- tests/system/utils/minicore-utils.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/system/utils/minicore-utils.sh b/tests/system/utils/minicore-utils.sh index 2805d54..c9740f0 100644 --- a/tests/system/utils/minicore-utils.sh +++ b/tests/system/utils/minicore-utils.sh @@ -81,11 +81,9 @@ function clean_crash_dump { sleep 1 - if [ ! -d ${CRASH_DUMP_PATH} ]; then - fail "${CRASH_DUMP_PATH} does not exist" + if [ -d ${CRASH_DUMP_PATH} ]; then + rm -rf ${CRASH_DUMP_PATH}/* fi - - rm -rf ${CRASH_DUMP_PATH}/* } function clean_logdump { -- 2.7.4 From 6335d12bb531b1f40bb8c88fe9bc5c7d643d69d5 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 14 Sep 2021 15:11:52 +0200 Subject: [PATCH 04/16] Relicense crash-manager to MIT This includes relicensing: - crash-manager - the standalone program, which uses libcrash-manager - libcrash-manager - library that contains most of the logic After this change libcrash-manager can be safely combined with GPL-2.0 binaries. Change-Id: I564837e3ffe7ae5291b8e92bf1199f6277e04017 --- src/crash-manager/crash-manager.c | 19 +++---------------- src/crash-manager/crash-manager.h | 24 ++++-------------------- src/crash-manager/crash-popup-launch.c | 17 ++--------------- src/crash-manager/dbus-util.h | 17 +++-------------- src/crash-manager/dbus_notify.c | 21 ++++----------------- src/crash-manager/main.c | 6 ++++++ src/crash-manager/so-info.c | 19 +++---------------- src/crash-manager/so-info.h | 23 ++++------------------- src/shared/bugreport-util.c | 19 +++---------------- src/shared/bugreport-util.h | 23 +++++------------------ src/shared/config.c | 17 +++-------------- src/shared/config.h | 25 ++++--------------------- src/shared/log.h | 24 ++++-------------------- src/shared/spawn.c | 16 ++-------------- src/shared/spawn.h | 20 +++----------------- src/shared/util.c | 18 +++--------------- src/shared/util.h | 26 +++++--------------------- 17 files changed, 61 insertions(+), 273 deletions(-) diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 8dd6a00..e12e5b8 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -1,21 +1,8 @@ -/* - * crash-manager +/* This file is part of libcrash-manager * - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd. - * - * 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. + * Copyright (c) 2016-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #include #include #include diff --git a/src/crash-manager/crash-manager.h b/src/crash-manager/crash-manager.h index a12f03e..ff4bdd3 100644 --- a/src/crash-manager/crash-manager.h +++ b/src/crash-manager/crash-manager.h @@ -1,23 +1,9 @@ -/* - * crash-manager +/* This file is part of crash manager * - * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * 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. + * Copyright (c) 2019-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - -#ifndef __CRASH_MANAGER_H__ -#define __CRASH_MANAGER_H__ +#pragma once #include #include @@ -63,5 +49,3 @@ bool crash_manager_livedump_pid(pid_t pid, const char *dump_reason, char *report void crash_manager_free(struct crash_info *cinfo); void crash_info_init(struct crash_info *cinfo); void free_crash_info(struct crash_info *cinfo); - -#endif diff --git a/src/crash-manager/crash-popup-launch.c b/src/crash-manager/crash-popup-launch.c index 4ec2663..f869d20 100644 --- a/src/crash-manager/crash-popup-launch.c +++ b/src/crash-manager/crash-popup-launch.c @@ -1,22 +1,9 @@ -/* - * crash-popup: request showing crash-popup via d-bus +/* crash-popup: request showing crash-popup via d-bus * This utility is separate exececutable to limit crash-manager dependencies. * * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * 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. + * SPDX-License-Identifier: MIT */ - #define LOG_TAG "CRASH_MANAGER" #include "shared/log.h" #include "dbus-util.h" diff --git a/src/crash-manager/dbus-util.h b/src/crash-manager/dbus-util.h index 14d953c..ea34d75 100644 --- a/src/crash-manager/dbus-util.h +++ b/src/crash-manager/dbus-util.h @@ -1,19 +1,8 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. +/* This file is part of crash-manager * - * 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. + * Copyright (c) 2019-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #pragma once #include "shared/log.h" diff --git a/src/crash-manager/dbus_notify.c b/src/crash-manager/dbus_notify.c index b4926ee..81f82f0 100644 --- a/src/crash-manager/dbus_notify.c +++ b/src/crash-manager/dbus_notify.c @@ -1,22 +1,9 @@ -/* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd. +/* Broadcast crash info via D-Bus + * This utility is separate exececutable to limit crash-manager dependencies * - * 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. - * - * Authors: Mateusz Moscicki - * Karol Lewandowski + * Copyright (c) 2016-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #define LOG_TAG "CRASH_MANAGER" #include "shared/log.h" #include "dbus-util.h" diff --git a/src/crash-manager/main.c b/src/crash-manager/main.c index 961bb18..953994a 100644 --- a/src/crash-manager/main.c +++ b/src/crash-manager/main.c @@ -1,3 +1,9 @@ +/* Standalone crash-manager program + * This program is supposed to be invoked directly by kernel (via kernel.core_patter= mechanism) + * + * Copyright (c) 2016-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT + */ #include #include #include diff --git a/src/crash-manager/so-info.c b/src/crash-manager/so-info.c index 03f01fb..d667e68 100644 --- a/src/crash-manager/so-info.c +++ b/src/crash-manager/so-info.c @@ -1,21 +1,8 @@ -/* - * build-ids - * - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * 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 +/* Collect metadata about crashed program using rpm db * - * 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. + * Copyright (c) 2018-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #include #include #include diff --git a/src/crash-manager/so-info.h b/src/crash-manager/so-info.h index 474a47c..e13d420 100644 --- a/src/crash-manager/so-info.h +++ b/src/crash-manager/so-info.h @@ -1,24 +1,9 @@ -/* - * build-ids +/* This file is part of crash-manager * - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * 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. + * Copyright (c) 2018-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - -#ifndef __SO_INFO_H__ -#define __SO_INFO_H__ +#pragma once void get_and_save_so_info(char *map_filename, char *out_file); GHashTable *get_app_name_from_map(char *map_path); -#endif diff --git a/src/shared/bugreport-util.c b/src/shared/bugreport-util.c index 2bccab0..605ac54 100644 --- a/src/shared/bugreport-util.c +++ b/src/shared/bugreport-util.c @@ -1,20 +1,8 @@ -/* - * bugreport-util - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * 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 +/* bugreport-util: Helper to send bugreport events * - * 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. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #include #include #include @@ -39,4 +27,3 @@ bool send_bugreport_created_event(const char *report_path) bundle_free(event_data); return res == DIAGNOSTICS_ERROR_NONE; } - diff --git a/src/shared/bugreport-util.h b/src/shared/bugreport-util.h index 8cb44d0..15d36d6 100644 --- a/src/shared/bugreport-util.h +++ b/src/shared/bugreport-util.h @@ -1,23 +1,10 @@ -/* - * bugreport-util - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * 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 +/* This file is part of crash-manager * - * 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. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ -#ifndef __BUGREPORT_UTIL_H__ -#define __BUGREPORT_UTIL_H__ +#pragma once + #include bool send_bugreport_created_event(const char *report_path); - -#endif // __BUGREPORT_UTIL_H__ diff --git a/src/shared/config.c b/src/shared/config.c index 947095f..b5c7b3d 100644 --- a/src/shared/config.c +++ b/src/shared/config.c @@ -1,18 +1,7 @@ -/* - * crash-manager - * Copyright (c) 2019 Samsung Electronics Co., Ltd. +/* Config file handling support * - * 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. + * Copyright (c) 2019-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ #include #include diff --git a/src/shared/config.h b/src/shared/config.h index a50c437..a9ead12 100644 --- a/src/shared/config.h +++ b/src/shared/config.h @@ -1,21 +1,9 @@ -/* - * crash-manager - * Copyright (c) 2019 Samsung Electronics Co., Ltd. +/* This file is part of crash-manager * - * 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. + * Copyright (c) 2019-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ -#ifndef __DEF_CONFIG_H_ -#define __DEF_CONFIG_H_ +#pragma once #include @@ -72,8 +60,3 @@ bool config_is_path_excluded(config_t *c, const char *const path); #ifdef __cplusplus } #endif - -/** - * @} - */ -#endif diff --git a/src/shared/log.h b/src/shared/log.h index 8ee72b2..c232c20 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -1,22 +1,9 @@ -/* - * crash-manager - * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +/* This file is part of crash-manager * - * 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. + * Copyright (c) 2012-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - -#ifndef __CRASH_LOG_H__ -#define __CRASH_LOG_H__ +#pragma once #ifndef LOG_TAG #define LOG_TAG "CRASH_MANAGER" @@ -56,6 +43,3 @@ static inline char __dlog_prio(int prio) #define _I(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_INFO) SLOGI(fmt, ##arg); } while (0) #define _W(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_WARN) SLOGW(fmt, ##arg); } while (0) #define _E(fmt, arg...) do { if (DLOG_LOG_LEVEL <= DLOG_ERROR) SLOGE(fmt, ##arg); } while (0) - -#endif -/* __CRASH_LOG_H__ */ diff --git a/src/shared/spawn.c b/src/shared/spawn.c index 392a053..3bfc34c 100644 --- a/src/shared/spawn.c +++ b/src/shared/spawn.c @@ -1,20 +1,8 @@ /* Utilities for spawning sub-processes * - * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd. - * - * 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. + * Copyright (c) 2018-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #include #include #include diff --git a/src/shared/spawn.h b/src/shared/spawn.h index 431b173..a365360 100644 --- a/src/shared/spawn.h +++ b/src/shared/spawn.h @@ -1,21 +1,9 @@ /* Utilities for spawning sub-processes * - * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd. - * - * 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. + * Copyright (c) 2018-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ -#ifndef __SPAWN_H__ -#define __SPAWN_H__ +#pragma once #include #include @@ -54,5 +42,3 @@ bool spawn_wait(char *const av[], char *const ev[], spawn_param_s *param, int ti #ifdef __cplusplus } #endif - -#endif diff --git a/src/shared/util.c b/src/shared/util.c index 778f0ad..da130e6 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1,20 +1,8 @@ -/* - * crash-manager - * Copyright (c) 2012-2019 Samsung Electronics Co., Ltd. +/* Misc. utility functions * - * 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. + * Copyright (c) 2012-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ - #include #include #include diff --git a/src/shared/util.h b/src/shared/util.h index 32609e0..af74c67 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -1,21 +1,9 @@ -/* - * crash-manager - * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +/* This file is part of crash-manager * - * 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. + * Copyright (c) 2012-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT */ -#ifndef __DEF_UTIL_H__ -#define __DEF_UTIL_H__ +#pragma once #include #include @@ -83,11 +71,7 @@ bool file_exists_in_dir(const char *dir_path, const char *file_name); bool write_to_file(const char *content, const char *base_dir, const char *file_name); bool is_dotnet_file(const char *path); + #ifdef __cplusplus } #endif - -/** - * @} - */ -#endif -- 2.7.4 From 28f7a8441933e6fa6be017d0ad276d040c30f387 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 16 Sep 2021 13:29:39 +0200 Subject: [PATCH 05/16] Add missing license header to crash-json2info Change-Id: Id9d16738ab457a78cba9192deb64b0640d39946c --- src/crash-json2info/crash-json2info.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/crash-json2info/crash-json2info.c b/src/crash-json2info/crash-json2info.c index 3c3c315..083e37e 100644 --- a/src/crash-json2info/crash-json2info.c +++ b/src/crash-json2info/crash-json2info.c @@ -1,3 +1,8 @@ +/* Standalone utility to convert crash report in .json format to legacy human-readable format + * + * Copyright (c) 2019-2021 Samsung Electronics Co., Ltd. + * SPDX-License-Identifier: MIT + */ #include #include #include -- 2.7.4 From 3e930e6c24105fcc75838e7b0ed9e1d3550dc8c3 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 16 Sep 2021 13:31:39 +0200 Subject: [PATCH 06/16] packaging: Update license specifications after relicensing parts of codebase Additionally, rename LICENSE to LICENSE.Apache-2.0 for clarity. Change-Id: If2eb9621ad0808970521d64a5dfe8099913ec2b3 --- LICENSE => LICENSE.Apache-2.0 | 0 packaging/crash-worker.spec | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) rename LICENSE => LICENSE.Apache-2.0 (100%) diff --git a/LICENSE b/LICENSE.Apache-2.0 similarity index 100% rename from LICENSE rename to LICENSE.Apache-2.0 diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 432bda1..caffbca 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -19,7 +19,7 @@ Summary: Coredump handler and report generator for Tizen Version: 6.5.21 Release: 1 Group: Framework/system -License: Apache-2.0 and BSD-2-Clause and MIT +License: MIT Source0: %{name}-%{version}.tar.gz Source1001: crash-worker.manifest BuildRequires: pkgconfig(dlog) @@ -65,10 +65,12 @@ Requires: %{name}-support-regdump = %{version}-%{release} %package dumpsystemstate-config Summary: common configuration for dump_systemstate utility and bugreport-service +License: MIT %description dumpsystemstate-config %package dumpsystemstate-util Summary: dump_systemstate utility used for dumping basic system information +License: Apache-2.0 and MIT Requires: %{name}-dumpsystemstate-config = %{version}-%{release} Requires: %{_bindir}/buxton2ctl # Ensure crash_worker user is available (created by security-config, package provides crash_worker-owned files) @@ -78,6 +80,7 @@ Requires: security-config %if %{with dumpsystemstateservice} %package dumpsystemstate-service Summary: service provides dumpsys provider to system state information +License: Apache-2.0 and MIT Requires: %{name}-dumpsystemstate-config = %{version}-%{release} %description dumpsystemstate-service %endif @@ -85,6 +88,7 @@ Requires: %{name}-dumpsystemstate-config = %{version}-%{release} %if %{with regdumper} %package support-regdump Summary: package provides components needed to support kernel-invoked coredump handling +License: MIT Requires: %{name}-support-common = %{version}-%{release} Requires: minicoredumper >= 2.1.0 # Ensure crash_worker user is available (created by security-config, package provides crash_worker-owned files) @@ -95,6 +99,7 @@ Requires: security-config %if %{with livedumper} %package support-livecoredump Summary: package provides components needed to support livecoredumps +License: Apache-2.0 and MIT Requires: %{name}-support-common = %{version}-%{release} Provides: %{name}-livedumper = %{version}-%{release} %description support-livecoredump @@ -102,6 +107,7 @@ Provides: %{name}-livedumper = %{version}-%{release} %package support-common Summary: package provides common components needed to support both kernel-invoked coredump and livedump +License: Apache-2.0 and BSD-2-Clause and MIT Requires: %{name}-dumpsystemstate-util = %{version}-%{release} Requires: zip # Ensure crash_worker user is available (created by security-config, package provides crash_worker-owned files) @@ -110,10 +116,12 @@ Requires: security-config %package -n libcrash-manager-devel Summary: package provides headers needed to develop programs using libcrash-manager +License: MIT %description -n libcrash-manager-devel %package -n bugreport-service Summary: bugreport provides dumpsys provider for diagnostics data +License: Apache-2.0 and MIT BuildRequires: pkgconfig(diagnostics) Requires: %{name}-dumpsystemstate-util = %{version}-%{release} %if %{with livedumper} @@ -278,18 +286,18 @@ chsmack -a "System" -t %{crash_root_path} chsmack -a "System" -t %{crash_path} %files -%license LICENSE +%license LICENSE.MIT %manifest crash-worker.manifest %files dumpsystemstate-util %manifest crash-worker.manifest -%license LICENSE +%license LICENSE.Apache-2.0 LICENSE.MIT # attr() needed because: dump_systemstate has Smack exec_label(=System) set and we don't want to allow everyone to abuse it %attr(0750,root,crash_worker) %{_bindir}/dump_systemstate %if %{with dumpsystemstateservice} %files dumpsystemstate-service -%license LICENSE +%license LICENSE.Apache-2.0 LICENSE.MIT %manifest crash-worker.manifest %{_bindir}/dump_systemstate-service %{_unitdir}/dump_systemstate.service @@ -298,13 +306,13 @@ chsmack -a "System" -t %{crash_path} %files dumpsystemstate-config %manifest crash-worker.manifest -%license LICENSE +%license LICENSE.MIT %{_sysconfdir}/dump_systemstate.conf.d/files/*.conf* %{_sysconfdir}/dump_systemstate.conf.d/programs/*.conf* %if %{with regdumper} %files support-regdump -%license LICENSE +%license LICENSE.MIT %manifest crash-worker.manifest %{_prefix}/lib/sysctl.d/70-crash-manager.conf # attr() needed because: crash-worker has Smack exec_label(=System::Privileged) set and we don't want to allow everyone to abuse it @@ -315,7 +323,7 @@ chsmack -a "System" -t %{crash_path} %if %{with livedumper} %files support-livecoredump -%license LICENSE +%license LICENSE.Apache-2.0 LICENSE.MIT %manifest crash-worker.manifest %manifest %{name}.manifest %{_bindir}/livedumper @@ -323,7 +331,7 @@ chsmack -a "System" -t %{crash_path} %if %{with livedumper} || %{with regdumper} %files support-common -%license LICENSE LICENSE.BSD LICENSE.MIT +%license LICENSE.Apache-2.0 LICENSE.BSD LICENSE.MIT %manifest crash-worker.manifest # attr() needed because: crash-worker running as crash_worker:crash_worker (user:group) creates files/dir under this path %attr(0775,crash_worker,crash_worker) %{crash_root_path} @@ -336,7 +344,7 @@ chsmack -a "System" -t %{crash_path} %{upgrade_script_path}/500.crash-manager-upgrade.sh %files -n libcrash-manager-devel -%license LICENSE +%license LICENSE.MIT %manifest crash-worker.manifest %{_includedir}/crash-manager.h %{_libdir}/libcrash-manager.so @@ -344,7 +352,7 @@ chsmack -a "System" -t %{crash_path} %endif %files -n bugreport-service -%license LICENSE +%license LICENSE.Apache-2.0 LICENSE.MIT %manifest crash-worker.manifest # attr() needed because: crash-worker running as crash_worker:crash_worker (user:group) creates files/dir under this path %attr(0775,crash_worker,crash_worker) %{crash_root_path} @@ -364,6 +372,7 @@ chsmack -a "System" -t %{crash_path} %if %{with tests} %files tests %manifest %{name}.manifest +%license LICENSE.MIT %{_libexecdir}/crash-worker/tests/test1-default-crash %{_libexecdir}/crash-worker/tests/test1-default-sleep %{_libexecdir}/crash-worker/tests/test1-default-ill @@ -376,6 +385,7 @@ chsmack -a "System" -t %{crash_path} %files system-tests %manifest %{name}.manifest +%license LICENSE.MIT %{_bindir}/crash-worker-system-tests-run %{_libexecdir}/crash-worker/system-tests/bugreport_crash_info_json/bugreport_crash_info_json.sh -- 2.7.4 From 76b1adba7d49e6f7d89900450429328831ed51f1 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 16 Sep 2021 13:33:44 +0200 Subject: [PATCH 07/16] packaging: Drop unneeded BuildRequires Not only it was in wrong section but there is already BuildRequires: pkgconfig(diagnostics) in top section. Change-Id: I66dac6e85a82f350c56675bd370c68a586d299bf --- packaging/crash-worker.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index caffbca..3f60a5b 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -122,7 +122,6 @@ License: MIT %package -n bugreport-service Summary: bugreport provides dumpsys provider for diagnostics data License: Apache-2.0 and MIT -BuildRequires: pkgconfig(diagnostics) Requires: %{name}-dumpsystemstate-util = %{version}-%{release} %if %{with livedumper} Requires: %{name}-support-livecoredump = %{version}-%{release} -- 2.7.4 From 218539ad6f7a851f91f773dbcdbd32f303297d49 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 16 Sep 2021 13:44:41 +0200 Subject: [PATCH 08/16] Release 6.5.22 Change-Id: Ib867761ec1c4089efd85f8e5f94a74f932d21683 --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 3f60a5b..d5b1fc0 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -16,7 +16,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 6.5.21 +Version: 6.5.22 Release: 1 Group: Framework/system License: MIT -- 2.7.4 From ea0c8698b5c0b30fd9581976c664d22f60a89cc3 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 4 Jan 2022 14:28:23 +0100 Subject: [PATCH 09/16] Remove 500.crash-manager-upgrade.sh This script prepares directories and permissions when upgrading from Tizen 5.5 to 6.0. Therefore it is no longer needed. Change-Id: I1c4b4baeea02c4b0c9ac4131da297352b72399ce --- packaging/crash-worker.spec | 2 -- src/crash-manager/500.crash-manager-upgrade.sh.in | 17 ----------------- src/crash-manager/CMakeLists.txt | 6 ------ 3 files changed, 25 deletions(-) delete mode 100644 src/crash-manager/500.crash-manager-upgrade.sh.in diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index d5b1fc0..39caae4 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -260,7 +260,6 @@ rm -f %{buildroot}%{_prefix}/lib/debug/usr/libexec/crash-stack.debug rm -f %{buildroot}%{_prefix}/lib/debug/usr/lib/libcrash-manager.so* rm -f %{buildroot}%{_includedir}/crash-manager.h rm -f %{buildroot}%{_prefix}/lib/pkgconfig/crash-manager.pc -rm -f %{buildroot}%{upgrade_script_path}/500.crash-manager-upgrade.sh %endif %post support-common @@ -340,7 +339,6 @@ chsmack -a "System" -t %{crash_path} %{_libexecdir}/crash-stack %{_sysconfdir}/crash-manager.conf %{_sysconfdir}/crash-manager.conf.d/crash-manager.conf.example -%{upgrade_script_path}/500.crash-manager-upgrade.sh %files -n libcrash-manager-devel %license LICENSE.MIT diff --git a/src/crash-manager/500.crash-manager-upgrade.sh.in b/src/crash-manager/500.crash-manager-upgrade.sh.in deleted file mode 100644 index 86b9130..0000000 --- a/src/crash-manager/500.crash-manager-upgrade.sh.in +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -#----------------------------------------------# -# crash-manager patch for upgrade (5.5 -> 6.0) # -#----------------------------------------------# - -PATH=/bin:/usr/bin:/sbin:/usr/sbin - -rm -rf /opt/usr/share/crash # Crash path of Tizen 5.5 - -mkdir -p @CRASH_ROOT_PATH@ -mkdir -p @CRASH_TEMP@ -mkdir -p @CRASH_PATH@ - -find @CRASH_ROOT_PATH@ -type d | xargs chsmack -a "System" -t -find @CRASH_ROOT_PATH@ -type d | xargs chmod 775 -find @CRASH_ROOT_PATH@ -type d | xargs chown crash_worker:crash_worker diff --git a/src/crash-manager/CMakeLists.txt b/src/crash-manager/CMakeLists.txt index b3629c1..17735bc 100644 --- a/src/crash-manager/CMakeLists.txt +++ b/src/crash-manager/CMakeLists.txt @@ -65,7 +65,6 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) -CONFIGURE_FILE(500.${PROJECT_NAME}-upgrade.sh.in 500.${PROJECT_NAME}-upgrade.sh @ONLY) CONFIGURE_FILE(70-${PROJECT_NAME}.conf.in 70-${PROJECT_NAME}.conf @ONLY) CONFIGURE_FILE(crash-manager.pc.in crash-manager.pc @ONLY) @@ -85,8 +84,3 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/crash-manager.pc INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/70-${PROJECT_NAME}.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/sysctl.d PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) - -INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}/500.${PROJECT_NAME}-upgrade.sh - DESTINATION ${UPGRADE_SCRIPT_PATH} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) -- 2.7.4 From 2d8a62a43119c50ac7b25558cad19c32d74d0abe Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 4 Jan 2022 14:57:30 +0100 Subject: [PATCH 10/16] Release 7.0.0 Change-Id: Ibb09b26050346252f4c8b7caeffbb0c804a60175 --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index 39caae4..b39ff99 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -16,7 +16,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 6.5.22 +Version: 7.0.0 Release: 1 Group: Framework/system License: MIT -- 2.7.4 From cb4b3392f64736b2a4a50c892794f1bf9383e877 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Wed, 12 Jan 2022 15:52:29 +0100 Subject: [PATCH 11/16] Fix the release of ELF data resources Change-Id: I66810a17c4fa04db981a6c325e6a054a334d0bfb --- src/shared/telf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/telf.c b/src/shared/telf.c index 87b5209..d987fc6 100644 --- a/src/shared/telf.c +++ b/src/shared/telf.c @@ -329,7 +329,7 @@ bool teu_close(Elf *elf) { assert(elf); - if (elf->status == TEU_MEMORY) + if (elf->status == TEU_FILE) munmap(elf->data, elf->data_size); return true; -- 2.7.4 From 73f6d904bd351b1b294a72608f046fff9fd7fbab Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Wed, 12 Jan 2022 16:16:08 +0100 Subject: [PATCH 12/16] Release 7.0.1 Change-Id: I4d0e812752f4d396668bbca7da1b6222c3261dff --- packaging/crash-worker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index b39ff99..6422b28 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -16,7 +16,7 @@ Name: crash-worker Summary: Coredump handler and report generator for Tizen -Version: 7.0.0 +Version: 7.0.1 Release: 1 Group: Framework/system License: MIT -- 2.7.4 From 18ae5652b1a745ece5696835f1d33ac077959fc5 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 3 Feb 2022 12:40:06 +0100 Subject: [PATCH 13/16] Fix realpath(3) memory leak Change-Id: Ic2e2264a8dab194884decfa5acb9035ea712b149 --- src/bugreport-service/diagnostics/diagnostics.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bugreport-service/diagnostics/diagnostics.c b/src/bugreport-service/diagnostics/diagnostics.c index f038cad..71df306 100644 --- a/src/bugreport-service/diagnostics/diagnostics.c +++ b/src/bugreport-service/diagnostics/diagnostics.c @@ -103,17 +103,21 @@ static bool is_report_file(const char *path, const char *reports_dir) if (access(r_path, F_OK) == -1) { _E("access() for %s error: %m\n", path); - return false; + goto out_err; } char *start = strstr(r_path, reports_dir); if (start == NULL) { _I("%s is not within %s\n", r_path, reports_dir); - return false; + goto out_err; } return true; + +out_err: + free(r_path); + return false; } static enum diagnostics_type check_report_type(const char *path) -- 2.7.4 From 96ea384249976280fd3ef930cdd4fe84e520da48 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 1 Dec 2022 12:34:48 +0100 Subject: [PATCH 14/16] Add support for RISC-V Change-Id: Id1cbadf09b55f7da416833981b0e14ce6202cd7e --- src/crash-manager/dbus_notify.c | 15 ++- src/crash-stack/CMakeLists.txt | 3 +- src/crash-stack/crash-stack-riscv64.c | 175 ++++++++++++++++++++++++++++++++++ src/crash-stack/crash-stack-stub.c | 1 + src/crash-stack/crash-stack.h | 2 + src/crash-stack/unwind.c | 3 + src/livedumper/core.hpp | 2 + src/livedumper/helpers.hpp | 1 + src/livedumper/livedumper.hpp | 3 +- src/livedumper/main.cpp | 4 +- src/livedumper/note.hpp | 2 + tests/test1.c | 2 + 12 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 src/crash-stack/crash-stack-riscv64.c diff --git a/src/crash-manager/dbus_notify.c b/src/crash-manager/dbus_notify.c index 81f82f0..eec8a0a 100644 --- a/src/crash-manager/dbus_notify.c +++ b/src/crash-manager/dbus_notify.c @@ -20,6 +20,7 @@ #include #include #include +#include #define CRASH_BUS_NAME "org.tizen.system.crash" #define CRASH_OBJECT_PATH "/Org/Tizen/System/Crash" @@ -77,7 +78,7 @@ static int _get_important_registers(int fd, struct RegInfo **reg_info) #if (defined __i386__) || (defined __x86_64__) count = 1; -#elif (defined __arm__) || (defined __aarch64__) +#elif (defined __arm__) || (defined __aarch64__) || ((defined __riscv) && __riscv_xlen == 64) count = 2; #endif @@ -126,6 +127,16 @@ static int _get_important_registers(int fd, struct RegInfo **reg_info) goto strdup_error; reginfo[1].value = (long long int)g_registers->regs[AARCH64_REG_LR]; +#elif defined(__riscv) && __riscv_xlen == 64 + + struct user_regs_struct *g_registers = (struct user_regs_struct*)prstatus->pr_reg; + + if ((reginfo[0].name = strdup("riscv.pc")) == NULL) + goto strdup_error; + reginfo[0].value = (long long int)g_registers->pc; + if ((reginfo[1].name = strdup("riscv.ra")) == NULL) + goto strdup_error; + reginfo[1].value = (long long int)g_registers->ra; #endif // (defined __i386__) || (defined __x86_64__) out: @@ -196,7 +207,7 @@ static GVariant *build_message_data(const struct NotifyParams *notify_params, co g_variant_builder_open(&md_builder, G_VARIANT_TYPE("{sv}")); g_variant_builder_add(&md_builder, "s", reg_info[i].name); -#if (defined __x86_64__) || (defined __aarch64__) +#if (defined __x86_64__) || (defined __aarch64__) || ((defined __riscv) && __riscv_xlen == 64) g_variant_builder_add(&md_builder, "v", g_variant_new_uint64(reg_info[i].value)); #else g_variant_builder_add(&md_builder, "v", g_variant_new_uint32(reg_info[i].value)); diff --git a/src/crash-stack/CMakeLists.txt b/src/crash-stack/CMakeLists.txt index d2a8dd8..6e00e88 100644 --- a/src/crash-stack/CMakeLists.txt +++ b/src/crash-stack/CMakeLists.txt @@ -16,7 +16,8 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") elseif ((${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")) set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-x86.c) - +elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64") + set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-riscv64.c) else() set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-stub.c) endif() diff --git a/src/crash-stack/crash-stack-riscv64.c b/src/crash-stack/crash-stack-riscv64.c new file mode 100644 index 0000000..084fee9 --- /dev/null +++ b/src/crash-stack/crash-stack-riscv64.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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. + * + * Authors: Adrian Szyndela + * Łukasz Stelmach + * Mateusz Moscicki + */ +/** + * @file crash-stack-riscv64.c + * @brief unwinding call stacks, functions specific for riscv64 + */ +#include "crash-stack.h" +#include "shared/log.h" +#include "shared/util.h" + +#include +#include +#include +#include +#include + +#define REG_RISCV_S0 8 +#define REG_RISCV_RA 1 + +static struct user_regs_struct g_registers; ///< static storage for registers + +/** + * @brief Important registers for unwinding stack on riscv64 + */ +struct Regs { + Elf64_Addr pc; ///< register: program counter + Elf64_Addr ra; ///< x1 register contains return address + Elf64_Addr sp; ///< x2 register: stack pointer + Elf64_Addr s0; ///< x8 register contains frame pointer +}; + +typedef struct Regs Regs; ///< convenience type definition +static Regs g_regs; ///< static storage for target register values + +void *_crash_stack_get_memory_for_registers(size_t *size) +{ + if (NULL != size) + *size = sizeof(g_registers); + return &g_registers; +} + +void _crash_stack_set_registers(void *regbuf) +{ + struct user_regs_struct *regs = regbuf; + + memcpy(_get_place_for_register_value("pc", REG_RISCV_PC), ®s->pc, sizeof(regs->pc)); + memcpy(_get_place_for_register_value("ra", REG_RISCV_RA), ®s->ra, sizeof(regs->ra)); + memcpy(_get_place_for_register_value("sp", REG_RISCV_SP), ®s->sp, sizeof(regs->sp)); + memcpy(_get_place_for_register_value("s0", REG_RISCV_S0), ®s->s0, sizeof(regs->s0)); +} + +void *_get_place_for_register_value(const char *regname, int regnum) +{ + if (strcmp(regname, "pc") == 0 || REG_RISCV_PC == regnum) + return &g_regs.pc; + else if (strcmp(regname, "ra") == 0 || REG_RISCV_RA == regnum) + return &g_regs.ra; + else if (strcmp(regname, "sp") == 0 || REG_RISCV_SP == regnum) + return &g_regs.sp; + else if (strcmp(regname, "s0") == 0 || REG_RISCV_S0 == regnum) + return &g_regs.s0; + return NULL; +} + +unsigned long _get_register_value(int n) +{ + // return g_registers.regs[n]; + const static int reg_map[] = { + [UNW_RISCV_X0] = offsetof(struct user_regs_struct, pc) / sizeof(long), + [UNW_RISCV_X1] = offsetof(struct user_regs_struct, ra) / sizeof(long), + [UNW_RISCV_X2] = offsetof(struct user_regs_struct, sp) / sizeof(long), + [UNW_RISCV_X3] = offsetof(struct user_regs_struct, gp) / sizeof(long), + [UNW_RISCV_X4] = offsetof(struct user_regs_struct, tp) / sizeof(long), + [UNW_RISCV_X5] = offsetof(struct user_regs_struct, t0) / sizeof(long), + [UNW_RISCV_X6] = offsetof(struct user_regs_struct, t1) / sizeof(long), + [UNW_RISCV_X7] = offsetof(struct user_regs_struct, t2) / sizeof(long), + [UNW_RISCV_X8] = offsetof(struct user_regs_struct, s0) / sizeof(long), + [UNW_RISCV_X9] = offsetof(struct user_regs_struct, s1) / sizeof(long), + [UNW_RISCV_X10] = offsetof(struct user_regs_struct, a0) / sizeof(long), + [UNW_RISCV_X11] = offsetof(struct user_regs_struct, a1) / sizeof(long), + [UNW_RISCV_X12] = offsetof(struct user_regs_struct, a2) / sizeof(long), + [UNW_RISCV_X13] = offsetof(struct user_regs_struct, a3) / sizeof(long), + [UNW_RISCV_X14] = offsetof(struct user_regs_struct, a4) / sizeof(long), + [UNW_RISCV_X15] = offsetof(struct user_regs_struct, a5) / sizeof(long), + [UNW_RISCV_X16] = offsetof(struct user_regs_struct, a6) / sizeof(long), + [UNW_RISCV_X17] = offsetof(struct user_regs_struct, a7) / sizeof(long), + [UNW_RISCV_X18] = offsetof(struct user_regs_struct, s2) / sizeof(long), + [UNW_RISCV_X19] = offsetof(struct user_regs_struct, s3) / sizeof(long), + [UNW_RISCV_X20] = offsetof(struct user_regs_struct, s4) / sizeof(long), + [UNW_RISCV_X21] = offsetof(struct user_regs_struct, s5) / sizeof(long), + [UNW_RISCV_X22] = offsetof(struct user_regs_struct, s6) / sizeof(long), + [UNW_RISCV_X23] = offsetof(struct user_regs_struct, s7) / sizeof(long), + [UNW_RISCV_X24] = offsetof(struct user_regs_struct, s8) / sizeof(long), + [UNW_RISCV_X25] = offsetof(struct user_regs_struct, s9) / sizeof(long), + [UNW_RISCV_X26] = offsetof(struct user_regs_struct, s10) / sizeof(long), + [UNW_RISCV_X27] = offsetof(struct user_regs_struct, s11) / sizeof(long), + [UNW_RISCV_X28] = offsetof(struct user_regs_struct, t3) / sizeof(long), + [UNW_RISCV_X29] = offsetof(struct user_regs_struct, t4) / sizeof(long), + [UNW_RISCV_X30] = offsetof(struct user_regs_struct, t5) / sizeof(long), + [UNW_RISCV_X31] = offsetof(struct user_regs_struct, t6) / sizeof(long), + }; + n = reg_map[n]; + return ((elf_greg_t*)&g_registers)[n]; +} + +void _crash_stack_print_regs(json_object *jobj) +{ + json_object *j_regs = json_object_new_array(); + + struct reg { + const char *name; + unsigned long long int value; + } regs[] = { + {"pc", g_registers.pc}, + {"ra", g_registers.ra}, + {"sp", g_registers.sp}, + {"gp", g_registers.gp}, + {"tp", g_registers.tp}, + {"t0", g_registers.t0}, + {"t1", g_registers.t1}, + {"t2", g_registers.t2}, + {"s0", g_registers.s0}, + {"s1", g_registers.s1}, + {"a0", g_registers.a0}, + {"a1", g_registers.a1}, + {"a2", g_registers.a2}, + {"a3", g_registers.a3}, + {"a4", g_registers.a4}, + {"a5", g_registers.a5}, + {"a6", g_registers.a6}, + {"a7", g_registers.a7}, + {"s2", g_registers.s2}, + {"s3", g_registers.s3}, + {"s4", g_registers.s4}, + {"s5", g_registers.s5}, + {"s6", g_registers.s6}, + {"s7", g_registers.s7}, + {"s8", g_registers.s8}, + {"s9", g_registers.s9}, + {"s10", g_registers.s10}, + {"s11", g_registers.s11}, + {"t3", g_registers.t3}, + {"t4", g_registers.t4}, + {"t5", g_registers.t5}, + {"t6", g_registers.t6}, + }; + + for (size_t i = 0; i < ARRAY_SIZE(regs); i++) { + char value_str[16+3]; + if (sprintf(value_str, "0x%016llx", regs[i].value) == -1) { + _E("Cannot print register value: %m"); + continue; + } + ADD_REG_TO_JSON_ARRAY(j_regs, regs[i].name, value_str); + } + + json_object_object_add(jobj, K_REGISTERS, j_regs); +} diff --git a/src/crash-stack/crash-stack-stub.c b/src/crash-stack/crash-stack-stub.c index ca1429c..b6ffbae 100644 --- a/src/crash-stack/crash-stack-stub.c +++ b/src/crash-stack/crash-stack-stub.c @@ -1,3 +1,4 @@ +#include #include "crash-stack.h" void *_crash_stack_get_memory_for_registers(size_t *size) diff --git a/src/crash-stack/crash-stack.h b/src/crash-stack/crash-stack.h index 765a16e..e7cc7cd 100644 --- a/src/crash-stack/crash-stack.h +++ b/src/crash-stack/crash-stack.h @@ -74,6 +74,8 @@ #define REG_AARCH64_PC 32 #define REG_ARM_SP 13 #define REG_ARM_PC 12 +#define REG_RISCV_SP 2 +#define REG_RISCV_PC 0 #define ADD_REG_TO_JSON_ARRAY(j_array, name, value) \ { \ diff --git a/src/crash-stack/unwind.c b/src/crash-stack/unwind.c index 3a2b455..a3f15cd 100644 --- a/src/crash-stack/unwind.c +++ b/src/crash-stack/unwind.c @@ -818,6 +818,9 @@ void _get_esp_and_eip() { #elif defined(__aarch64__) esp_i = REG_AARCH64_SP; // values from crash-stack-aarch64.c eip_i = REG_AARCH64_PC; +#elif defined(__riscv) && __riscv_xlen == 64 + esp_i = REG_RISCV_SP; // values from crash-stack-riscv64.c + eip_i = REG_RISCV_PC; #else #error "Not supported architecture" #endif diff --git a/src/livedumper/core.hpp b/src/livedumper/core.hpp index 3c3b7d2..37a79db 100644 --- a/src/livedumper/core.hpp +++ b/src/livedumper/core.hpp @@ -477,6 +477,8 @@ class Core { result = registers[task_nr].uregs[13]; #elif defined(__aarch64__) result = registers[task_nr].sp; +#elif defined(__riscv) && __riscv_xlen == 64 + result = registers[task_nr].sp; #else #error Unsupported architecture #endif diff --git a/src/livedumper/helpers.hpp b/src/livedumper/helpers.hpp index f7f0cb5..36f8e87 100644 --- a/src/livedumper/helpers.hpp +++ b/src/livedumper/helpers.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/livedumper/livedumper.hpp b/src/livedumper/livedumper.hpp index 4b83703..01bcb1a 100644 --- a/src/livedumper/livedumper.hpp +++ b/src/livedumper/livedumper.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -107,7 +108,7 @@ class LiveDumper { } void GetRegs(user_regs_struct *registers, pid_t pid) const { -#if defined(__aarch64__) +#if defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) struct iovec iov = { registers, sizeof *registers }; if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov) == -1) #else diff --git a/src/livedumper/main.cpp b/src/livedumper/main.cpp index b29b566..b98a264 100644 --- a/src/livedumper/main.cpp +++ b/src/livedumper/main.cpp @@ -25,9 +25,9 @@ #include #include -#if defined(__arm__) || defined(__i386__) +#if defined(__arm__) || defined(__i386__) || (defined(__riscv) && __riscv_xlen == 32) #define ELF_TYPE Elf32 -#elif defined(__x86_64__) || defined(__aarch64__) +#elif defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) #define ELF_TYPE Elf64 #endif diff --git a/src/livedumper/note.hpp b/src/livedumper/note.hpp index 9cc8f92..9758e76 100644 --- a/src/livedumper/note.hpp +++ b/src/livedumper/note.hpp @@ -39,6 +39,8 @@ typedef user_regs user_regs_struct; #define MACHINE EM_X86_64 #elif defined(__i386__) #define MACHINE EM_386 +#elif defined(__riscv) && __riscv_xlen == 64 +#define MACHINE EM_RISCV #else #error "architecture unsupported" #endif diff --git a/tests/test1.c b/tests/test1.c index 6b5f1b1..bf51a8b 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -16,6 +16,8 @@ char ill_buf[] = { 0xf0, 0x00, 0x00, 0xf0 }; char ill_buf[] = { 0x22, 0x00, 0x00, 0xf9 }; #elif defined(__i386__) || defined(__x86_64__) char ill_buf[] = { 0x06, 0x00, 0x00, 0x00 }; +#elif defined(__riscv) && __riscv_xlen == 64 +char ill_buf[] = { 0x06, 0x00, 0x00, 0x00 }; #else #error "Unsupported architecture" #endif -- 2.7.4 From 7741baeb21ce380e48b32d0665c74da2e8fa6dfc Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 14 Mar 2023 13:56:53 +0100 Subject: [PATCH 15/16] Fix SVACE issuses Change-Id: I371e7a235ce5502d8a5f01cdfecac509efac7cc9 --- src/crash-stack/crash-stack-arm.c | 2 +- src/crash-stack/mem_map.c | 12 +----------- src/crash-stack/proc.c | 8 +------- src/livedumper/core.hpp | 6 +++++- src/livedumper/note.hpp | 15 ++++++++++++++- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/crash-stack/crash-stack-arm.c b/src/crash-stack/crash-stack-arm.c index 11eb0fa..a1032f7 100644 --- a/src/crash-stack/crash-stack-arm.c +++ b/src/crash-stack/crash-stack-arm.c @@ -121,7 +121,7 @@ void _crash_stack_print_regs(json_object *jobj) for (size_t i = 0; i < ARRAY_SIZE(regs); i++) { char value_str[8+3]; - if (sprintf(value_str, "0x%08lx", g_registers.uregs[regs[i].index]) == -1) { + if (snprintf(value_str, ARRAY_SIZE(value_str), "0x%08lx", g_registers.uregs[regs[i].index]) == -1) { _E("Cannot print register value: %m"); continue; } diff --git a/src/crash-stack/mem_map.c b/src/crash-stack/mem_map.c index 66e721c..bc60f73 100644 --- a/src/crash-stack/mem_map.c +++ b/src/crash-stack/mem_map.c @@ -46,11 +46,6 @@ #define VSYSCALL_START (-10UL << 20) #endif -// extern int opt_verbose; -// extern int opt_ignore_deleted; -static int opt_verbose = 1; -static int opt_ignore_deleted = 0; - static void mem_region_print(const struct mem_region *region); static int in(const void *point, const void *start, size_t size) @@ -493,9 +488,7 @@ static int mem_region_read_word(struct mem_region *region, return -1; case MEM_REGION_TYPE_DELETED: - if (!opt_ignore_deleted) - return -2; - break; + return -2; case MEM_REGION_TYPE_MMAP: if (region->fd < 0 && mem_region_map_file(region) < 0) @@ -523,9 +516,6 @@ static int mem_region_read_word(struct mem_region *region, if (chunk == NULL) { size_t i; - if (!opt_verbose) - return -1; - _E("No chunk of memory containing %p at region %p-%p", addr, region->start, region->start + region->length); mem_region_print(region); diff --git a/src/crash-stack/proc.c b/src/crash-stack/proc.c index 9174960..62bb548 100644 --- a/src/crash-stack/proc.c +++ b/src/crash-stack/proc.c @@ -85,7 +85,6 @@ extern struct timeval unfreeze_time; /* extern int opt_verbose; */ static int opt_proc_mem = 0; -static int opt_verbose = 0; int proc_state(int pid) { @@ -457,12 +456,7 @@ int copy_memory(int pid, struct mem_data_chunk **frames, int n_frames) { if (!opt_proc_mem) { int rc = copy_memory_process_vm_readv(pid, frames, n_frames); - if (rc == ENOSYS) { - if (opt_verbose) { - _E("process_vm_readv is not supported, falling " - "back to /proc/pid/mem"); - } - } else { + if (rc != ENOSYS) { return rc; } } diff --git a/src/livedumper/core.hpp b/src/livedumper/core.hpp index 37a79db..d084b08 100644 --- a/src/livedumper/core.hpp +++ b/src/livedumper/core.hpp @@ -217,7 +217,11 @@ class Core { void ReadFromFile(std::ifstream &input, unsigned long address, void *data, size_t len) { input.seekg(address, std::ios_base::beg); - input.read(static_cast(data), len); + if (len > std::numeric_limits::max()) { + logger.log_error("Such a large data cannot be read"); + } else { + input.read(static_cast(data), len); + } } void ReadFromFile(const int fd, unsigned long address, void *data, size_t len) { diff --git a/src/livedumper/note.hpp b/src/livedumper/note.hpp index 9758e76..65e112f 100644 --- a/src/livedumper/note.hpp +++ b/src/livedumper/note.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #if defined(__arm__) typedef user_regs user_regs_struct; @@ -175,7 +176,19 @@ class NoteCoreAUXV : public Note { desc_size = m_auxv.size(); } void SaveDataTo(std::ofstream &core_file) const { - core_file.write(m_auxv.data(), m_auxv.size()); + std::vector::size_type remaining = m_auxv.size(); + std::vector::size_type offset = 0; + while (remaining > 0) { + std::streamsize chunk_size; + if (remaining > std::numeric_limits::max()) { + chunk_size = std::numeric_limits::max(); + } else { + chunk_size = remaining; + } + remaining -= chunk_size; + core_file.write(m_auxv.data() + offset, chunk_size); + offset += chunk_size; + } } const std::vector& auxv() const { -- 2.7.4 From 29271aa755826c15ab52000fdf9c337c7d56e562 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 14 Mar 2023 16:55:32 +0100 Subject: [PATCH 16/16] Fix build issue on armv7l related to ptrace() Change-Id: Ia33eefb96b7f98c9c983f236d30c6dc643b88d1a --- src/livedumper/helpers.hpp | 1 - src/livedumper/livedumper.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/livedumper/helpers.hpp b/src/livedumper/helpers.hpp index 36f8e87..f7f0cb5 100644 --- a/src/livedumper/helpers.hpp +++ b/src/livedumper/helpers.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/src/livedumper/livedumper.hpp b/src/livedumper/livedumper.hpp index 01bcb1a..60de125 100644 --- a/src/livedumper/livedumper.hpp +++ b/src/livedumper/livedumper.hpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include -- 2.7.4