Merge branch 'master' into security
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
commit
ad58db0721
158 changed files with 6915 additions and 3361 deletions
|
@ -101,12 +101,17 @@ set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|||
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
list(APPEND headers
|
||||
"${include_path}/dds/ddsrt/avl.h"
|
||||
"${include_path}/dds/ddsrt/fibheap.h"
|
||||
"${include_path}/dds/ddsrt/hopscotch.h"
|
||||
"${include_path}/dds/ddsrt/thread_pool.h"
|
||||
"${include_path}/dds/ddsrt/log.h"
|
||||
"${include_path}/dds/ddsrt/retcode.h"
|
||||
"${include_path}/dds/ddsrt/attributes.h"
|
||||
"${include_path}/dds/ddsrt/endian.h"
|
||||
"${include_path}/dds/ddsrt/arch.h"
|
||||
"${include_path}/dds/ddsrt/misc.h"
|
||||
"${include_path}/dds/ddsrt/mh3.h"
|
||||
"${include_path}/dds/ddsrt/io.h"
|
||||
"${include_path}/dds/ddsrt/process.h"
|
||||
"${include_path}/dds/ddsrt/dynlib.h"
|
||||
|
@ -114,7 +119,8 @@ list(APPEND headers
|
|||
"${include_path}/dds/ddsrt/strtol.h"
|
||||
"${include_path}/dds/ddsrt/types.h"
|
||||
"${include_path}/dds/ddsrt/countargs.h"
|
||||
"${include_path}/dds/ddsrt/static_assert.h")
|
||||
"${include_path}/dds/ddsrt/static_assert.h"
|
||||
"${include_path}/dds/ddsrt/circlist.h")
|
||||
|
||||
list(APPEND sources
|
||||
"${source_path}/bswap.c"
|
||||
|
@ -122,21 +128,15 @@ list(APPEND sources
|
|||
"${source_path}/log.c"
|
||||
"${source_path}/retcode.c"
|
||||
"${source_path}/strtod.c"
|
||||
"${source_path}/strtol.c")
|
||||
|
||||
list(APPEND headers
|
||||
"${include_path}/dds/ddsrt/avl.h"
|
||||
"${include_path}/dds/ddsrt/fibheap.h"
|
||||
"${include_path}/dds/ddsrt/hopscotch.h"
|
||||
"${include_path}/dds/ddsrt/thread_pool.h")
|
||||
|
||||
list(APPEND sources
|
||||
"${source_path}/strtol.c"
|
||||
"${source_path}/mh3.c"
|
||||
"${source_path}/avl.c"
|
||||
"${source_path}/expand_envvars.c"
|
||||
"${source_path}/fibheap.c"
|
||||
"${source_path}/hopscotch.c"
|
||||
"${source_path}/thread_pool.c"
|
||||
"${source_path}/xmlparser.c")
|
||||
"${source_path}/xmlparser.c"
|
||||
"${source_path}/circlist.c")
|
||||
|
||||
# Not every target offers the same set of features. For embedded targets the
|
||||
# set of features may even be different between builds. e.g. a FreeRTOS build
|
||||
|
|
43
src/ddsrt/include/dds/ddsrt/circlist.h
Normal file
43
src/ddsrt/include/dds/ddsrt/circlist.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2019 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_CIRCLIST_H
|
||||
#define DDSRT_CIRCLIST_H
|
||||
|
||||
/* Circular doubly linked list implementation */
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DDSRT_FROM_CIRCLIST(typ_, member_, cle_) ((typ_ *) ((char *) (cle_) - offsetof (typ_, member_)))
|
||||
|
||||
struct ddsrt_circlist {
|
||||
struct ddsrt_circlist_elem *latest; /* pointer to latest inserted element */
|
||||
};
|
||||
|
||||
struct ddsrt_circlist_elem {
|
||||
struct ddsrt_circlist_elem *next;
|
||||
struct ddsrt_circlist_elem *prev;
|
||||
};
|
||||
|
||||
DDS_EXPORT void ddsrt_circlist_init (struct ddsrt_circlist *list);
|
||||
DDS_EXPORT bool ddsrt_circlist_isempty (const struct ddsrt_circlist *list);
|
||||
DDS_EXPORT void ddsrt_circlist_append (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem);
|
||||
DDS_EXPORT void ddsrt_circlist_remove (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem);
|
||||
DDS_EXPORT struct ddsrt_circlist_elem *ddsrt_circlist_oldest (const struct ddsrt_circlist *list);
|
||||
DDS_EXPORT struct ddsrt_circlist_elem *ddsrt_circlist_latest (const struct ddsrt_circlist *list);
|
||||
|
||||
#endif /* DDSRT_CIRCLIST_H */
|
34
src/ddsrt/include/dds/ddsrt/mh3.h
Normal file
34
src/ddsrt/include/dds/ddsrt/mh3.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_MH3_H
|
||||
#define DDSRT_MH3_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DDS_EXPORT uint32_t
|
||||
ddsrt_mh3(
|
||||
const void *key,
|
||||
size_t len,
|
||||
uint32_t seed);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DDSRT_MH3_H */
|
|
@ -43,7 +43,7 @@ extern "C" {
|
|||
/** Absolute Time definition */
|
||||
typedef int64_t dds_time_t;
|
||||
|
||||
/** Relative Time definition */
|
||||
/** Relative Time definition in nanoseconds */
|
||||
typedef int64_t dds_duration_t;
|
||||
|
||||
/** @name Macro definition for time units in nanoseconds.
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <VersionHelpers.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -119,7 +119,7 @@ extern inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_
|
|||
#endif
|
||||
extern inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des);
|
||||
extern inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des);
|
||||
#if DDSRT_ATOMIC_LIFO_SUPPORT
|
||||
#if DDSRT_HAVE_ATOMIC_LIFO
|
||||
extern inline int ddsrt_atomic_casvoidp2 (volatile ddsrt_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1);
|
||||
#endif
|
||||
/* FENCES */
|
||||
|
@ -129,7 +129,7 @@ extern inline void ddsrt_atomic_fence_stst (void);
|
|||
extern inline void ddsrt_atomic_fence_acq (void);
|
||||
extern inline void ddsrt_atomic_fence_rel (void);
|
||||
|
||||
#if DDSRT_ATOMIC_LIFO_SUPPORT
|
||||
#if DDSRT_HAVE_ATOMIC_LIFO
|
||||
void ddsrt_atomic_lifo_init (ddsrt_atomic_lifo_t *head)
|
||||
{
|
||||
head->aba_head.s.a = head->aba_head.s.b = 0;
|
||||
|
|
84
src/ddsrt/src/circlist.c
Normal file
84
src/ddsrt/src/circlist.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2019 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "dds/ddsrt/circlist.h"
|
||||
|
||||
void ddsrt_circlist_init (struct ddsrt_circlist *list)
|
||||
{
|
||||
list->latest = NULL;
|
||||
}
|
||||
|
||||
bool ddsrt_circlist_isempty (const struct ddsrt_circlist *list)
|
||||
{
|
||||
return list->latest == NULL;
|
||||
}
|
||||
|
||||
void ddsrt_circlist_append (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem)
|
||||
{
|
||||
if (list->latest == NULL)
|
||||
elem->next = elem->prev = elem;
|
||||
else
|
||||
{
|
||||
struct ddsrt_circlist_elem * const hd = list->latest;
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
const struct ddsrt_circlist_elem *x = hd;
|
||||
do { assert (x != elem); x = x->next; } while (x != hd);
|
||||
}
|
||||
#endif
|
||||
elem->next = hd->next;
|
||||
elem->prev = hd;
|
||||
hd->next = elem;
|
||||
elem->next->prev = elem;
|
||||
}
|
||||
list->latest = elem;
|
||||
}
|
||||
|
||||
void ddsrt_circlist_remove (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
const struct ddsrt_circlist_elem *x = list->latest;
|
||||
assert (x);
|
||||
do { if (x == elem) break; x = x->next; } while (x != list->latest);
|
||||
assert (x == elem);
|
||||
}
|
||||
#endif
|
||||
if (elem->next == elem)
|
||||
list->latest = NULL;
|
||||
else
|
||||
{
|
||||
struct ddsrt_circlist_elem * const elem_prev = elem->prev;
|
||||
struct ddsrt_circlist_elem * const elem_next = elem->next;
|
||||
elem_prev->next = elem_next;
|
||||
elem_next->prev = elem_prev;
|
||||
if (list->latest == elem)
|
||||
list->latest = elem_prev;
|
||||
}
|
||||
}
|
||||
|
||||
struct ddsrt_circlist_elem *ddsrt_circlist_oldest (const struct ddsrt_circlist *list)
|
||||
{
|
||||
assert (!ddsrt_circlist_isempty (list));
|
||||
return list->latest->next;
|
||||
}
|
||||
|
||||
struct ddsrt_circlist_elem *ddsrt_circlist_latest (const struct ddsrt_circlist *list)
|
||||
{
|
||||
assert (!ddsrt_circlist_isempty (list));
|
||||
return list->latest;
|
||||
}
|
||||
|
||||
|
69
src/ddsrt/src/mh3.c
Normal file
69
src/ddsrt/src/mh3.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include "dds/ddsrt/mh3.h"
|
||||
|
||||
#define DDSRT_MH3_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
|
||||
|
||||
/* Really
|
||||
http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp,
|
||||
MurmurHash3_x86_32
|
||||
*/
|
||||
uint32_t ddsrt_mh3 (const void *key, size_t len, uint32_t seed)
|
||||
{
|
||||
const uint8_t *data = (const uint8_t *) key;
|
||||
const intptr_t nblocks = (intptr_t) (len / 4);
|
||||
const uint32_t c1 = 0xcc9e2d51;
|
||||
const uint32_t c2 = 0x1b873593;
|
||||
|
||||
uint32_t h1 = seed;
|
||||
const uint32_t *blocks = (const uint32_t *) (data + nblocks * 4);
|
||||
for (intptr_t i = -nblocks; i; i++)
|
||||
{
|
||||
uint32_t k1 = blocks[i];
|
||||
|
||||
k1 *= c1;
|
||||
k1 = DDSRT_MH3_ROTL32 (k1, 15);
|
||||
k1 *= c2;
|
||||
|
||||
h1 ^= k1;
|
||||
h1 = DDSRT_MH3_ROTL32 (h1, 13);
|
||||
h1 = h1 * 5 + 0xe6546b64;
|
||||
}
|
||||
|
||||
const uint8_t *tail = data + nblocks * 4;
|
||||
uint32_t k1 = 0;
|
||||
switch (len & 3)
|
||||
{
|
||||
case 3:
|
||||
k1 ^= (uint32_t) tail[2] << 16;
|
||||
/* FALLS THROUGH */
|
||||
case 2:
|
||||
k1 ^= (uint32_t) tail[1] << 8;
|
||||
/* FALLS THROUGH */
|
||||
case 1:
|
||||
k1 ^= (uint32_t) tail[0];
|
||||
k1 *= c1;
|
||||
k1 = DDSRT_MH3_ROTL32 (k1, 15);
|
||||
k1 *= c2;
|
||||
h1 ^= k1;
|
||||
/* FALLS THROUGH */
|
||||
};
|
||||
|
||||
/* finalization */
|
||||
h1 ^= (uint32_t) len;
|
||||
h1 ^= h1 >> 16;
|
||||
h1 *= 0x85ebca6b;
|
||||
h1 ^= h1 >> 13;
|
||||
h1 *= 0xc2b2ae35;
|
||||
h1 ^= h1 >> 16;
|
||||
return h1;
|
||||
}
|
|
@ -39,6 +39,7 @@ typedef struct {
|
|||
} thread_context_t;
|
||||
|
||||
#if defined(__linux)
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <dirent.h>
|
||||
#define MAXTHREADNAMESIZE (15) /* 16 bytes including null-terminating byte. */
|
||||
|
@ -72,9 +73,10 @@ ddsrt_thread_getname(char *str, size_t size)
|
|||
assert(size > 0);
|
||||
|
||||
#if defined(__linux)
|
||||
/* Thread names are limited to 16 bytes on Linux. ERANGE is returned if the
|
||||
buffer is smaller than 16 bytes. Use an intermediate buffer. */
|
||||
(void)pthread_getname_np(pthread_self(), buf, sizeof(buf));
|
||||
/* Thread names are limited to 16 bytes on Linux, which the buffer should
|
||||
allow space for. prctl is favored over pthread_getname_np for
|
||||
portability. e.g. musl libc. */
|
||||
(void)prctl(PR_GET_NAME, (unsigned long)buf, 0UL, 0UL, 0UL);
|
||||
cnt = ddsrt_strlcpy(str, buf, size);
|
||||
#elif defined(__APPLE__)
|
||||
/* pthread_getname_np on APPLE uses strlcpy to copy the thread name, but
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue