forked from ros2/rcutils
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* micro-ROS changes over dashing Feature/add security directory (#1) * Added security directory * Updated security directory Feature/avoid filesystem and allocation (#2) * Included RCUTILS_NO_FILESYSTEM and RCUTILS_AVOID_DYNAMIC_ALLOCATION * Added no filesystem options * Default allocators write access * Avoid dynamic allocation and no filesytem on error handling * Typo * New flags for filesystem and avoid dynamic * Error handling template * New allocator approach Add test_security_directory test from rcl. (#3) Merge pull request #4 from micro-ROS/feature/zephyr_fixes Feature/zephyr fixes CMake refactor (#5) Update approach (#6) * Update approach * Remove target_compile_definitions and refactor flags install * Added RCUTILS_NO_FILESYSTEM on new functions * Added RCUTILS_NO_FILESYSTEM on new functions Co-authored-by: Pablo Garrido <pablogs9@gmail.com> Updates 17092020 Fix atomics 64bits (#9) * micro-ROS changes over dashing Feature/add security directory (#1) * Added security directory * Updated security directory Feature/avoid filesystem and allocation (#2) * Included RCUTILS_NO_FILESYSTEM and RCUTILS_AVOID_DYNAMIC_ALLOCATION * Added no filesystem options * Default allocators write access * Avoid dynamic allocation and no filesytem on error handling * Typo * New flags for filesystem and avoid dynamic * Error handling template * New allocator approach Add test_security_directory test from rcl. (#3) Merge pull request #4 from micro-ROS/feature/zephyr_fixes Feature/zephyr fixes CMake refactor (#5) Update approach (#6) * Update approach * Remove target_compile_definitions and refactor flags install * Added RCUTILS_NO_FILESYSTEM on new functions * Added RCUTILS_NO_FILESYSTEM on new functions Co-authored-by: Pablo Garrido <pablogs9@gmail.com> * Initial changes * Add hashing and lock pool * Updates Co-authored-by: Jose Antonio Moral <joseantoniomoralparras@gmail.com> Fix atomics 64bits (#9) Updates 09102020 * Release micro-ROS Foxy (#8) Update Cleaning
- Loading branch information
Showing
13 changed files
with
326 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#ifndef RCUTILS__CONFIGURATION_FLAGS_H_ | ||
#define RCUTILS__CONFIGURATION_FLAGS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#cmakedefine RCUTILS_NO_FILESYSTEM | ||
#cmakedefine RCUTILS_AVOID_DYNAMIC_ALLOCATION | ||
#cmakedefine RCUTILS_NO_THREAD_SUPPORT | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RCUTILS__CONFIGURATION_FLAGS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2018 Open Source Robotics Foundation, Inc. | ||
// | ||
// 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 RCUTILS__SECURITY_DIRECTORY_H_ | ||
#define RCUTILS__SECURITY_DIRECTORY_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include "rcutils/allocator.h" | ||
#include "rcutils/visibility_control.h" | ||
|
||
#ifndef ROS_SECURITY_NODE_DIRECTORY_VAR_NAME | ||
#define ROS_SECURITY_NODE_DIRECTORY_VAR_NAME "ROS_SECURITY_NODE_DIRECTORY" | ||
#endif | ||
|
||
#ifndef ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME | ||
#define ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "ROS_SECURITY_ROOT_DIRECTORY" | ||
#endif | ||
|
||
#ifndef ROS_SECURITY_LOOKUP_TYPE_VAR_NAME | ||
#define ROS_SECURITY_LOOKUP_TYPE_VAR_NAME "ROS_SECURITY_LOOKUP_TYPE" | ||
#endif | ||
|
||
/// Return the secure root directory associated with a node given its validated name and namespace. | ||
/** | ||
* E.g. for a node named "c" in namespace "/a/b", the secure root path will be | ||
* "a/b/c", where the delimiter "/" is native for target file system (e.g. "\\" for _WIN32). | ||
* If no exact match is found for the node name, a best match would be used instead | ||
* (by performing longest-prefix matching). | ||
* | ||
* However, this expansion can be overridden by setting the secure node directory environment | ||
* variable, allowing users to explicitly specify the exact secure root directory to be utilized. | ||
* Such an override is useful for where the FQN of a node is non-deterministic before runtime, | ||
* or when testing and using additional tools that may not otherwise be easily provisioned. | ||
* | ||
* \param[in] node_name validated node name (a single token) | ||
* \param[in] node_namespace validated, absolute namespace (starting with "/") | ||
* \param[in] allocator the allocator to use for allocation | ||
* \returns machine specific (absolute) node secure root path or NULL on failure | ||
* returned pointer must be deallocated by the caller of this function | ||
*/ | ||
RCUTILS_PUBLIC | ||
char * rcutils_get_secure_root( | ||
const char * node_name, | ||
const char * node_namespace, | ||
const rcutils_allocator_t * allocator | ||
); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RCUTILS__SECURITY_DIRECTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// 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. | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#define FLAGS_LEN 23 | ||
|
||
static bool * get_memory_lock(void *address) | ||
{ | ||
static bool memory_locks[FLAGS_LEN] = { 0 }; | ||
uintptr_t a = (uintptr_t)(address); | ||
|
||
// Public domain hash function taken from http://burtleburtle.net/bob/hash/integer.html | ||
a = (a ^ 61) ^ (a >> 16); | ||
a = a + (a << 3); | ||
a = a ^ (a >> 4); | ||
a = a * 0x27d4eb2d; | ||
a = a ^ (a >> 15); | ||
|
||
a = a % FLAGS_LEN; | ||
return memory_locks + a; | ||
} | ||
|
||
void lock_memory(uint64_t *address){ | ||
bool * memory_lock = get_memory_lock(address); | ||
|
||
while (__atomic_test_and_set(memory_lock, __ATOMIC_ACQUIRE) == 1); | ||
} | ||
|
||
void unlock_memory(uint64_t *address){ | ||
bool * memory_lock = get_memory_lock(address); | ||
|
||
__atomic_clear(memory_lock, __ATOMIC_RELEASE); | ||
} | ||
|
||
uint64_t __atomic_load_8(uint64_t *mem, int model) { | ||
(void) model; | ||
|
||
lock_memory(mem); | ||
uint64_t ret = *mem; | ||
unlock_memory(mem); | ||
return ret; | ||
} | ||
|
||
void __atomic_store_8(uint64_t *mem, uint64_t val, int model) { | ||
(void) model; | ||
|
||
lock_memory(mem); | ||
*mem = val; | ||
unlock_memory(mem); | ||
} | ||
|
||
uint64_t __atomic_exchange_8(uint64_t *mem, uint64_t val, int model) { | ||
(void) model; | ||
|
||
lock_memory(mem); | ||
uint64_t ret = *mem; | ||
*mem = val; | ||
unlock_memory(mem); | ||
return ret; | ||
} | ||
|
||
uint64_t __atomic_fetch_add_8(uint64_t *mem, uint64_t val, int model) { | ||
(void) model; | ||
|
||
lock_memory(mem); | ||
uint64_t ret = *mem; | ||
*mem += val; | ||
unlock_memory(mem); | ||
return ret; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.