From 811b430d0d6e20c57e3fb12fd457323d9d2249f1 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov <65451602+astrophysik@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:33:49 +0300 Subject: [PATCH] sync k2 header (#1084) --- .../kphp-light/unsupported/crypto.txt | 4 -- runtime-light/header.h | 70 +++++++++++-------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/builtin-functions/kphp-light/unsupported/crypto.txt b/builtin-functions/kphp-light/unsupported/crypto.txt index 54341483c7..6c8c0becc1 100644 --- a/builtin-functions/kphp-light/unsupported/crypto.txt +++ b/builtin-functions/kphp-light/unsupported/crypto.txt @@ -39,8 +39,4 @@ function openssl_sign ($data ::: string, &$signature ::: string, $priv_key_id :: /** @kphp-extern-func-info generate-stub */ function openssl_verify ($data ::: string, $signature ::: string, $pub_key_id ::: string, $signature_alg ::: int = 1) ::: int; /** @kphp-extern-func-info generate-stub */ -function openssl_random_pseudo_bytes ($length ::: int) ::: string | false; -/** @kphp-extern-func-info generate-stub */ -function openssl_x509_parse ($x509cert ::: string, $shortnames ::: bool = true) ::: mixed[] | false; -/** @kphp-extern-func-info generate-stub */ function openssl_x509_verify ($x509cert ::: string, $public_key ::: string) ::: int; diff --git a/runtime-light/header.h b/runtime-light/header.h index 5bae9daf93..1d498ad26f 100644 --- a/runtime-light/header.h +++ b/runtime-light/header.h @@ -17,7 +17,7 @@ #include #endif -#define K2_PLATFORM_HEADER_H_VERSION 6 +#define K2_PLATFORM_HEADER_H_VERSION 7 // Always check that enum value is a valid value! @@ -64,16 +64,20 @@ enum TimerStatus { enum OpenStreamResult { OpenStreamOk = 0, - // TODO: really need error? MB it's better to open and immediately close - // channel with corresponding error + /* + * TODO: really need error? MB it's better to open and immediately close + * channel with corresponding error + */ OpenStreamErrorInvalidName = 1, OpenStreamErrorUnknownComponent = 3, OpenStreamErrorComponentUnavailable = 4, OpenStreamErrorLimitExceeded = 5, }; -// This time point is valid only within the component. -// Similar to c++ `std::chrono::steady_clock::time_point` +/* + * This time point is valid only within the component. + * Similar to c++ `std::chrono::steady_clock::time_point` + */ struct TimePoint { uint64_t time_point_ns; }; @@ -95,7 +99,13 @@ struct PlatformCtx { /* * Immediately abort component execution. * Function is `[[noreturn]]` + * Note: `exit_code` used just as indicator for now. + * `exit_code` == 0 => FinishedOk, + * `exit_code` != 0 => FinishedError, */ + void (*exit)(int32_t exit_code); + + // Deprecated; Synonym for `exit(255)`; void (*abort)(); struct Allocator allocator; @@ -107,8 +117,7 @@ struct PlatformCtx { * `stream_d` will be assigned `0`. * however `stream_d=0` itself is not an error marker */ - enum OpenStreamResult (*open)(size_t name_len, const char *name, - uint64_t *stream_d); + enum OpenStreamResult (*open)(size_t name_len, const char *name, uint64_t *stream_d); /* * If the write or read status is `Blocked` - then the platform ensures that * the component receives this `stream_d` via `take_update` when the status is @@ -118,8 +127,7 @@ struct PlatformCtx { * `new_status` will be assigned as * `{.read_status = 0, .write_status = 0, .please_shutdown = 0}`. */ - enum GetStatusResult (*get_stream_status)(uint64_t stream_d, - struct StreamStatus *new_status); + enum GetStatusResult (*get_stream_status)(uint64_t stream_d, struct StreamStatus *new_status); /* * Return processed bytes (written or read). * Guaranteed to return `0` if the stream is `Closed`, `Blocked` or @@ -133,6 +141,7 @@ struct PlatformCtx { */ size_t (*write)(uint64_t stream_d, size_t data_len, const void *data); size_t (*read)(uint64_t stream_d, size_t data_len, void *data); + /* * Sets `StreamStatus.please_whutdown_write=true` for the component on the * opposite side (does not affect `StreamStatus` on your side). @@ -141,6 +150,7 @@ struct PlatformCtx { * as long as `read_status != IOClosed`. */ void (*please_shutdown_write)(uint64_t stream_d); + /* * Disables the ability to write to a stream. * Data written to the stream buffer is still available for reading on the @@ -150,6 +160,7 @@ struct PlatformCtx { * TODO: design information errors. */ void (*shutdown_write)(uint64_t stream_d); + /* * "Free" associated descriptor. * All future uses of this `descriptor` will be invalid. @@ -175,6 +186,7 @@ struct PlatformCtx { // Coordinated with timers. Monotonical, for timeouts, measurements, etc.. void (*get_time)(struct TimePoint *time_point); + /* * In case of `result == Ok` timer_d will be NonZero * In case of `result != Ok` timer_d will be `0` @@ -183,6 +195,7 @@ struct PlatformCtx { * Use `free_descriptor` to cancel */ enum SetTimerResult (*set_timer)(uint64_t *timer_d, uint64_t duration_ns); + /* * It is guaranteed that if `TimerStatusElapsed` is returned * then `deadline <= get_time()` @@ -190,8 +203,7 @@ struct PlatformCtx { * * `deadline` will be assigned `0` if `timer_d` invalid */ - enum TimerStatus (*get_timer_status)(uint64_t timer_d, - struct TimePoint *deadline); + enum TimerStatus (*get_timer_status)(uint64_t timer_d, struct TimePoint *deadline); /* * Return: `bool`. * If `True`: the update was successfully received. @@ -211,6 +223,7 @@ struct PlatformCtx { * platform is guaranteed to reschedule it. */ uint8_t (*take_update)(uint64_t *update_d); + /* * Only utf-8 string supported. * Possible `level` values: @@ -220,19 +233,23 @@ struct PlatformCtx { * 4 => Debug * 5 => Trace * Any other value will cause the log to be skipped - */ - void (*log)(size_t level, size_t len, const char *str); - /* * if `level` > `log_level_enabled()` log will be skipped */ + void (*log)(size_t level, size_t len, const char *str); + + // Use for optimization, see `log` size_t (*log_level_enabled)(); + + // Note: prefer to use only as seed generator for pseudo-random + void (*os_rnd)(size_t len, void *bytes); }; struct ComponentState; + /* - * Image state created once on library load - * shared between all component [instances]. - * designed to prevent heavy `_init` section of dlib + * Image state created once on library load. + * Shared between all component [instances]. + * Designed to prevent heavy `_init` section of dlib */ struct ImageState; @@ -262,18 +279,13 @@ struct ImageInfo { }; // Every image should provide these symbols -enum PollStatus vk_k2_poll(const struct ImageState *image_state, - const struct PlatformCtx *pt_ctx, - struct ComponentState *component_ctx); - -// platform_ctx without IO stuff (nullptr instead io-functions) -// for now, returning nullptr will indicate error -struct ComponentState * -vk_k2_create_component_state(const struct ImageState *image_state, - const struct PlatformCtx *pt_ctx); - -// platform_ctx without IO stuff (nullptr instead io-functions) -// for now, returning nullptr will indicate error +enum PollStatus vk_k2_poll(const struct ImageState *image_state, const struct PlatformCtx *pt_ctx, struct ComponentState *component_ctx); + +/* + * platform_ctx without IO stuff (nullptr instead io-functions) + * for now, returning nullptr will indicate error + */ +struct ComponentState *vk_k2_create_component_state(const struct ImageState *image_state, const struct PlatformCtx *pt_ctx); struct ImageState *vk_k2_create_image_state(const struct PlatformCtx *pt_ctx); const struct ImageInfo *vk_k2_describe();