| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-03-29 22:05:51 +08:00
										 |  |  |  * Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <openssl/crypto.h>
 | 
					
						
							|  |  |  | #include "internal/e_os.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* system-specific variants defining OSSL_sleep() */ | 
					
						
							|  |  |  | #if defined(OPENSSL_SYS_UNIX) || defined(__DJGPP__)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-17 19:45:32 +08:00
										 |  |  | # if defined(OPENSSL_USE_USLEEP)                        \
 | 
					
						
							|  |  |  |     || defined(__DJGPP__)                               \ | 
					
						
							|  |  |  |     || (defined(__TANDEM) && defined(_REENTRANT)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * usleep() was made obsolete by POSIX.1-2008, and nanosleep() | 
					
						
							|  |  |  |  * should be used instead.  However, nanosleep() isn't implemented | 
					
						
							|  |  |  |  * on the platforms given above, so we still use it for those. | 
					
						
							|  |  |  |  * Also, OPENSSL_USE_USLEEP can be defined to enable the use of | 
					
						
							|  |  |  |  * usleep, if it turns out that nanosleep() is unavailable. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #  include <unistd.h>
 | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | void OSSL_sleep(uint64_t millis) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-04-17 19:45:32 +08:00
										 |  |  |     unsigned int s = (unsigned int)(millis / 1000); | 
					
						
							|  |  |  |     unsigned int us = (unsigned int)((millis % 1000) * 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s > 0) | 
					
						
							|  |  |  |         sleep(s); | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * On NonStop with the PUT thread model, thread context switch is | 
					
						
							|  |  |  |      * cooperative, with usleep() being a "natural" context switch point. | 
					
						
							|  |  |  |      * We avoid checking us > 0 here, to allow that context switch to | 
					
						
							|  |  |  |      * happen. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     usleep(us); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-22 05:16:11 +08:00
										 |  |  | # elif defined(__TANDEM) && !defined(_REENTRANT)
 | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-17 19:45:32 +08:00
										 |  |  | #  include <cextdecs.h(PROCESS_DELAY_)>
 | 
					
						
							|  |  |  | void OSSL_sleep(uint64_t millis) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  |     /* HPNS does not support usleep for non threaded apps */ | 
					
						
							|  |  |  |     PROCESS_DELAY_(millis * 1000); | 
					
						
							| 
									
										
										
										
											2024-04-17 19:45:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | # else
 | 
					
						
							| 
									
										
										
										
											2023-05-23 00:51:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-17 19:45:32 +08:00
										 |  |  | /* nanosleep is defined by POSIX.1-2001 */ | 
					
						
							|  |  |  | #  include <time.h>
 | 
					
						
							|  |  |  | void OSSL_sleep(uint64_t millis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct timespec ts; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ts.tv_sec = (long int) (millis / 1000); | 
					
						
							|  |  |  |     ts.tv_nsec = (long int) (millis % 1000) * 1000000ul; | 
					
						
							|  |  |  |     nanosleep(&ts, NULL); | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-17 19:45:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # endif
 | 
					
						
							| 
									
										
										
										
											2023-04-11 23:31:57 +08:00
										 |  |  | #elif defined(_WIN32) && !defined(OPENSSL_SYS_UEFI)
 | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | # include <windows.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSSL_sleep(uint64_t millis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * Windows' Sleep() takes a DWORD argument, which is smaller than | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  |      * a uint64_t, so we need to limit it to 49 days, which should be enough. | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  |     DWORD limited_millis = (DWORD)-1; | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  |     if (millis < limited_millis) | 
					
						
							|  |  |  |         limited_millis = (DWORD)millis; | 
					
						
							|  |  |  |     Sleep(limited_millis); | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | #else
 | 
					
						
							|  |  |  | /* Fallback to a busy wait */ | 
					
						
							|  |  |  | # include "internal/time.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ossl_sleep_secs(uint64_t secs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * sleep() takes an unsigned int argument, which is smaller than | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  |      * a uint64_t, so it needs to be limited to 136 years which | 
					
						
							|  |  |  |      * should be enough even for Sleeping Beauty. | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  |     unsigned int limited_secs = UINT_MAX; | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:16:33 +08:00
										 |  |  |     if (secs < limited_secs) | 
					
						
							|  |  |  |         limited_secs = (unsigned int)secs; | 
					
						
							|  |  |  |     sleep(limited_secs); | 
					
						
							| 
									
										
											  
											
												Rename ossl_sleep() to OSSL_sleep() and make it public
ossl_sleep() was implemented as a static inline function in internal/e_os.h,
using usleep() on Unix and Sleep() on Windows.  So far well and good.
However, it also has a fallback implementation for systems that do not have
usleep() or Sleep(), and that implementation happens to use ossl_time_now(),
which is a normal function, private to libcrypto, and is judged to be too
complex to sanely make into a static inline function.
This fallback creates a problem, because we do use ossl_sleep() in apps/ and
a few test programs in test/, and when they are linked with libcrypto in
shared library form, ossl_time_now() can't be found, since it's not publicly
exposed.
Something needs to give, and the easiest, and hopefully sanest answer is to
make ossl_sleep() a publicly exposed function, which requires a slight name
change.
Documentation and 'make update' result included.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19330)
											
										 
											2022-10-03 13:10:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ossl_sleep_millis(uint64_t millis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const OSSL_TIME finish | 
					
						
							|  |  |  |         = ossl_time_add(ossl_time_now(), ossl_ms2time(millis)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (ossl_time_compare(ossl_time_now(), finish) < 0) | 
					
						
							|  |  |  |         /* busy wait */ ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSSL_sleep(uint64_t millis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ossl_sleep_secs(millis / 1000); | 
					
						
							|  |  |  |     ossl_sleep_millis(millis % 1000); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* defined(OPENSSL_SYS_UNIX) || defined(__DJGPP__) */
 |