Commit Graph
496 Commits
Author SHA1 Message Date
Martin Willi f3c809e615 windows: Provide a strndup(3) replacement 2014-06-04 15:53:02 +02:00
Martin Willi 110e42361e unit-tests: Uninline dlopen() and friends, make more dynamic, fix dlerror()
As the error string contains a newline, we have to remove that before
returning the string.
2014-06-04 15:53:02 +02:00
Martin Willi a48570a046 windows: Provide a cancellable usleep(), but with ms resolution only 2014-06-04 15:53:01 +02:00
Martin Willi 986a577097 windows: Add a sleep function acting as cancellation point 2014-06-04 15:53:01 +02:00
Martin Willi 266ee0a190 windows: Provide a sched_yield() implementation 2014-06-04 15:53:01 +02:00
Martin Willi 4de7401a98 windows: Provide a time_monotonic() based on GetTickCount64() 2014-06-04 15:53:01 +02:00
Martin Willi c46cee6f6d chunk: Don't depend on pthread directly 2014-06-04 15:53:00 +02:00
Martin Willi f1c9653e04 utils: Don't directly depend on pthread 2014-06-04 15:53:00 +02:00
Martin Willi eb94f58595 strerror: Don't directly depend on pthread 2014-06-04 15:53:00 +02:00
Martin Willi a506b922f3 windows: Provide a strdup variant safe when passing zero-length strings 2014-06-04 15:53:00 +02:00
Martin Willi aa5b49c037 stream: Separate TCP/Unix stream helpers from stream/service implementations
This allows us to disable Unix sockets cleanly on Windows. Replaces some
read/write calls with recv/send counterparts, as Winsock does not like
read/writes.
2014-06-04 15:53:00 +02:00
Martin Willi df0769299a windows: Map WSAGetLastError() to errno failures in wrapped send/recv/from/to 2014-06-04 15:52:59 +02:00
Martin Willi 20021277f2 windows: Add send/recv and sendto/recvfrom wrappers supporting MSG_DONTWAIT 2014-06-04 15:52:59 +02:00
Martin Willi 82fcb80276 windows: Implement socketpair() using TCP sockets 2014-06-04 15:52:59 +02:00
Martin Willi 87a79e6a03 windows: Add utils_init/deinit functions to initialize Winsock2 2014-06-04 15:52:59 +02:00
Martin Willi fb81820796 windows: Provide a setenv() wrapper 2014-06-04 15:52:59 +02:00
Martin Willi a2216a2868 windows: Fix up PRI* printf formatters when building against own backend 2014-06-04 15:52:58 +02:00
Martin Willi 95a8d53dbe windows: Use localtime/gmtime to implement _r variants
The _s variants and friends do not seem to work on Windows 7 and always fail.
2014-06-04 15:52:58 +02:00
Martin Willi 8f129319ff utils: Printf() defined time output should gmtime/localtime_r() fail 2014-06-04 15:52:58 +02:00
Martin Willi 087e02e47e backtrace: Inline esc() helper, making it available to all build variants 2014-06-04 15:52:58 +02:00
Martin Willi 2127831cda backtrace: Support backtraces on Windows without DbgHelp
While DbgHelp provides a convenient API to create backtraces, any executable
linking against DbgHelp gets a more than a significant slow down. Further, it
can only lookup global symbols, as it expects PDB files we can't produce with a
MinGW build.

With some core Kernel32.dll functionality, we can capture stack traces much
faster. Together with the optional libbfd, we can print very fine backtraces.

When --enable-bfd-backtraces is used on Windows, a libbfd.dll is required for
the build. Such a DLL can be created from the binutils sources using:

  # build binutils with mingw...

  # extract archive members from binutils libraries
  x86_64-w64-mingw32-ar x $BINUTILS/bfd/.libs/libbfd.a
  x86_64-w64-mingw32-ar x $BINUTILS/intl/libintl.a
  x86_64-w64-mingw32-ar x $BINUTILS/libiberty/libiberty.a

  # create self-contained libbfd.a, with index
  x86_64-w64-mingw32-ar qs libbfd.a *.o

  # create DLL from static library
  x86_64-w64-mingw32-dlltool -e libbfd.o -l libbfd.lib libbfd.a
  x86_64-w64-mingw32-gcc -shared libbfd.a libbfd.o -o libbfd.dll
2014-06-04 15:52:58 +02:00
Martin Willi a7e943a640 backtrace: Add DbgHelp based Windows support for creating/printing backtraces 2014-06-04 15:52:57 +02:00
Martin Willi 1f2b8c8c80 printf-hook-builtin: Support Windows console colors using TTY escape codes 2014-06-04 15:52:57 +02:00
Martin Willi e7f3ceb7c8 capabilities: Add build support for Windows
We might extend it in the future using some Windows rights management.
2014-06-04 15:52:57 +02:00
Martin Willi d3c30b356c windows: Use _getmaxstdio as replacement for syscall(_SC_OPEN_MAX) 2014-06-03 12:24:35 +02:00
Martin Willi a3f7dfc1ca windows: replace mkdir() with Windows _mkdir() variant 2014-06-03 12:24:35 +02:00
Martin Willi 2e6c203bad windows: Provide wrappers for dlopen() function family 2014-06-03 12:24:34 +02:00
Martin Willi 922ee2c529 windows: Add a common Windows header for platform specific wrappers
Include some more basic system headers in utils.h, so we can use that common
header on the different platforms.
2014-06-03 12:24:34 +02:00
Martin Willi 064fe9c963 enum: Return boolean result for enum_from_name() lookup
Handling the result for enum_from_name() is difficult, as checking for
negative return values requires a cast if the enum type is unsigned. The new
signature clearly differentiates lookup result from lookup value.

Further, this actually allows to convert real -1 enum values, which could not
be distinguished from "not-found" and the -1 return value.

This also fixes several clang warnings where enums are unsigned.
2014-05-16 15:42:07 +02:00
Martin Willi 9ee8b3b41f enum: Don't directly include enum.h
To allow enum.h to depend on utils.h definitions, avoid its direct inclusion.
Instead include utils.h, which includes enum.h as well.
2014-05-16 15:42:07 +02:00
Tobias Brunner 4102fc9c09 parser-helper: Define debug macros depending on DEBUG_LEVEL 2014-05-15 11:28:10 +02:00
Tobias Brunner 66248396c6 parser-helper: Make parser_helper_file_t private 2014-05-15 11:28:10 +02:00
Tobias Brunner c976cc7d33 parser-helper: Make parser_helper_log a function 2014-05-15 11:28:10 +02:00
Tobias Brunner f65ac98c64 settings: Reduce log verbosity if files can't be opened
Basically reintroducing 2a38b4556e.
2014-05-15 11:28:09 +02:00
Tobias Brunner 3cb8016f0e parser-helper: Add utility class for flex/bison based parsers 2014-05-15 11:28:06 +02:00
Tobias Brunner b9b1114ab1 settings: Move to a separate folder 2014-05-15 11:28:05 +02:00
Martin Willi 9e93251397 utils: Provide a CALLBACK macro, similar to METHOD, but for void* callbacks
Using the same mechanism as the METHOD macro, the CALLBACK macro defines
a hybrid function signature. It strictly uses a weak void* for the first
function parameter, in contrast to the dynamic METHOD object "this" type.
2014-05-07 14:13:34 +02:00
Tobias Brunner a0c2370ea5 utils: Enable __atomic* built-ins based on the GCC version
This solves a problem with GNAT when compiling charon-tkm as __atomic*
built-ins are only provided in GCC 4.7 and newer.

Currently GNAT 4.6 and GCC 4.7.2 is shipped with Debian wheezy (stable),
as used in the testing environment.  So while the configure script correctly
detected the __atomic* built-ins, and defined HAVE_GCC_ATOMIC_OPERATIONS,
this define turned out to be incorrect when charon-tkm was later built
with GNAT.
2014-05-04 19:16:46 +02:00
Tobias Brunner 0f603d425d utils: Use GCC's __atomic built-ins if available
These are available since GCC 4.7 and will eventually replace the __sync
operations.  They support the memory model defined by C++11. For instance,
by using __ATOMIC_RELAXED for some operations on the reference counters we
can avoid memory barriers, which are required by __sync operations (whose
memory model essentially is __ATOMIC_SEQ_CST).
2014-04-24 17:54:14 +02:00
Tobias Brunner efedd0d21e utils: Add ref_cur() to retrieve the current value of a reference counter
On many architectures it is safe to read the value directly (those
using cache coherency protocols, and with atomic loads for 32-bit
values) but it is not if that's not the case or if we ever decide to
make refcount_t 64-bit (load not atomic on x86).

So make sure the operation is actually atomic and that users do not
have to care about the size of refcount_t.
2014-04-24 17:53:42 +02:00
Tobias Brunner adc1157487 leak-detective: LEAK_DETECTIVE_DISABLE completely disables LD
If lib->leak_detective is non-null some code parts (e.g. the plugin
loader) assume LD is actually used.
2014-04-03 09:44:26 +02:00
Tobias Brunner 036dab0a10 unit-tests: Always load address of testable functions
The addresses can actually change as plugins are loaded/unloaded for
each test case.

Fixes #551.
2014-03-31 17:00:22 +02:00
Tobias Brunner 2a38b4556e settings: Reduce log verbosity if strongswan.conf does not exist
In some situations we expect strongswan.conf to not exist, for instance,
when running the unit tests before installation.
2014-03-31 16:40:04 +02:00
Tobias Brunner b751f6f25a unit-tests: Implement registered functions without __builtin_apply()
This makes the tests work with clang, which does not implement said
builtin.
2014-03-20 15:37:44 +01:00
Tobias Brunner 2c687b3cb3 unit-tests: Prefix imported testable functions with TEST_
This avoids any clashes with existing functions in the monolithic build.
2014-03-20 15:29:27 +01:00
Tobias Brunner f51169eb09 unit-tests: Change how hashtable for testable functions is created
Because GCC does not adhere to the priorities defined for constructors
when building with --enable-monolithic (not sure if it was just luck
that it worked in non-monolithic mode - anyway, it's not very portable)
function registration would fail because the hashtable would not be
created yet.
2014-03-20 15:29:27 +01:00
Tobias Brunner d517a9893e settings: Log all errors on level 1
Closes #539.
2014-03-04 13:30:09 +01:00
Thomas Egerer 7acdebf6c0 settings: Avoid conf file parsing beyond allocated buffer
A valgrind analysis of libstrongswan revealed an invalid read of 1 in
the function starts_with(). A more thorough analysis proved this to be
true and showed that with a specially crafted config file (e.g. a single
'#'-character not followed by a newline), the parser might even
interpret the random memory contents following the allocated buffer as
part of the configuration file.
The way the parser is designed, it must be able to skip an inserted
'\0' and continue parsing. Since it is not able to skip two '\0'
characters, the 'fix' of allocating two more bytes than the size of the
parsed file and setting them to '\0' seems to be a safe bet.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2014-03-03 17:27:58 +01:00
Tobias Brunner 2ed241aeb3 utils: Add memrchr(3) replacement for platforms that don't support it
For instance, on Mac OS X memrchr(3) is not provided by the C library.
2014-02-26 11:05:07 +01:00
Tobias Brunner 18019a3b89 settings: Use thread-safe dirname(3) 2014-02-24 12:04:11 +01:00