-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gmtime_r and mbedtls_time on Windows #1198
Conversation
@NWilson Thank you for your continuous contributions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR introduces valuable changes, especially the synchronization problem fix. Additionally it cleans up some legacy code, however before it is merged two things must be done:
- please remove the obsolete mutex definition,
- add entry in the changelog crediting yourself as the contributor.
Also for the sake of backporting the removal of the WinAPI timing function use should be considered before this can be merged.
include/mbedtls/threading.h
Outdated
@@ -96,7 +96,6 @@ extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); | |||
* Global mutexes | |||
*/ | |||
extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; | |||
extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs to be accompanied by an analogous change in threading.c
. The remaining definition is the reason for the CI failure.
#if defined(MBEDTLS_HAVE_TIME) | ||
#include "mbedtls/platform_time.h" | ||
#endif | ||
|
||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes the code a lot cleaner, however it will prevent us from backporting it as it definitely breaks WinCE compatibility. If you whish this PR to be backported to 2.7 and 2.1 versions please withdraw this change. Otherwise it is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with no backporting, so I've left this change in. It's not an urgent fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a functional change to a feature, and is more an improvement than a bug fix, so no backport is necessary in my view.
@NWilson Thanks for your contribution! I checked for the reason the CI fails and I found a minor issue with the PR. I've put more detailed commets in the form of a review. Would you be willing to introduce the suggested changes? |
I've updated the PR by rebasing it, removing the mutex definition, and re-running the tests. Thanks for the review. Sorry for lumping two different issues together here (gmtime_r and |
Thank you for a quick response (a lot quicker than ours, sorry for the delay on our side)! The PR looks good now; I will arrange for the ultimate reviews once we've got a result from the CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would opt for adding a test using -std=c99.
If we're extending the compatibility, it would be nice to make sure it does not break in the future. What do you think, @sbutcher-arm ?
I'm not sure how to add a test - it would involve adding something to the scripts run from |
Bump - there are no existing tests for compilation using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor review point.
library/entropy_poll.c
Outdated
@@ -19,6 +19,11 @@ | |||
* This file is part of mbed TLS (https://tls.mbed.org) | |||
*/ | |||
|
|||
#if defined(__linux) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be __linux__
. I believe __linux
is obsolete, although I haven't found an authoritative source on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted, I hadn't realised, but you're right.
#if defined(MBEDTLS_HAVE_TIME) | ||
#include "mbedtls/platform_time.h" | ||
#endif | ||
|
||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a functional change to a feature, and is more an improvement than a bug fix, so no backport is necessary in my view.
library/net_sockets.c
Outdated
@@ -19,6 +19,11 @@ | |||
* This file is part of mbed TLS (https://tls.mbed.org) | |||
*/ | |||
|
|||
/* Enable definition of getaddrinfo() even when compiling with -std=c99. Must | |||
* be set before config.h, which pulls in features.h indirectly. Harmless on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by features.h
. Do you mean MBEDTLS_USER_CONFIG_FILE
? Or do you mean a glibc specific header? Could you please clarify the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the Linux features.h
header, which is part of the Linux POSIX visibility system. See man feature_test_macros
. I'll clarify the comment.
I'm a bit concerned how this PR will work with Mbed OS, and what support there is in Mbed OS for cc: @k-stachowiak Also in response to @NWilson's question concerning the |
@sbutcher-arm @NWilson I can test the two PRs interaction on an RTC enabled device on Monday. |
I can't find the relevant mbedOS documentation. What libc does it use? It looks like it might use newlib in future, but doesn't currently, and I can't find any reference to the standard C functions provided by mbedOS. Unless mbedOS is living under a rock, gmtime_r should be available if gmtime is. This shouldn't have any relation to Real-Time Clock support; gmtime is a hardware-independent algorithm that doesn't need to know about the current time at all. I agree we don't want to break mbedOS, but I wouldn't expect it to (I can't test given I don't have any ARM boards or simulators set up). |
I have verified in practise that the |
Following @NWilson additional commits, can you please re-review? |
Dismissing review, as it's stale due to subsequent work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found one blocker (missing define in a Makefile - easily fixable), one potential minor issue (unnecessary constant in one of the defines), and have a minor suggestion.
I must request changes due to the blocking issue.
library/x509.c
Outdated
@@ -29,6 +29,10 @@ | |||
* http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf | |||
*/ | |||
|
|||
/* Ensure gmtime_r is available even with -std=c99; must be included before | |||
* config.h, which pulls in glibc's features.h. Harmless on other platforms. */ | |||
#define _XOPEN_SOURCE 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find a reference saying that _XOPEN_SOURCE
needs to be defined as 500 for gm_time_r; it merely needs to be defined. Unless there is an actual need for the specific value please remove the 500
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@k-stachowiak You are only partially right. Removing the 500
literal will cause other standard functions not to be available during the build.
tests/CMakeLists.txt
Outdated
# Enable definition of various functions used throughout the testsuite | ||
# (hostname, strdup, fileno...) even when compiling with -std=c99. Harmless | ||
# on non-POSIX platforms. | ||
add_definitions("-D_POSIX_C_SOURCE=200809L") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must also be added in the Makefile.
This could be provided in tests/scripts/generate_code.pl
for the consistency - having all the feature macros in the source files. However I do not have a strong opinion on this.
@NWilson - As ever, your contributions are very welcome. If you don't have time for responding to the review comments or doing any rework, please let us know and we'll pick this up and finish it off for you. |
In each place where POSIX/GNU functions are used, the file must declare that it wants POSIX functionality before including any system headers.
Sorry, it just took me a while to get round to it! The changes were small, I've done them now and re-run the build. Also rebased to fix a conflict in the ChangeLog file. I didn't edit the commits, the changes are contained in the final commit for ease of reviewing. Thanks! |
Thanks @NWilson! Hopefully we can get it in this time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing the comments. Unfortunately I was wrong on one of the remarks, in the way that it breaks our build in gcc 4.8.4. Could you please revert the change that I pointed out in a review comment? Otherwise the PR looks good to me.
library/x509.c
Outdated
@@ -31,7 +31,7 @@ | |||
|
|||
/* Ensure gmtime_r is available even with -std=c99; must be included before | |||
* config.h, which pulls in glibc's features.h. Harmless on other platforms. */ | |||
#define _XOPEN_SOURCE 500 | |||
#define _XOPEN_SOURCE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently I was overzealous with request for this change. It turns out that snprintf
requires one of the following:
_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
So unfortunately this change needs to be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've rolled back that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now.
retest |
I have investigated the FreeBSD build issue on a VM. The problem is, that, contrary to what has been documented in some places, Looking here reveals, that in order to unlock this part of the API, we need to get the @NWilson For your convenience, I have submitted a PR with a relevant change to your clone. If you don't have any objections, you may merge it there, which in turn should lead to the commit being submitted here. |
retest |
@sbutcher-arm @AndrzejKurek The CI tests have passed. Could you please review the new changes that made it possible? |
…cleanup [Backport] Buffer sharing cleanup
This PR fixes a couple of issues:
mbedtls_time
platform abstraction does not work, because for some reason thetime()
API is not used on Windows? I can't think of any reason not to use it, the Windows time implementation ought to go through the same platform abstraction layer as any other feature.-std=c99
. There are a couple of existing places in the code where this is broken, plusgmtime_r
adds another one.Issue: #704