Skip to content

Commit

Permalink
sync k2 header (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik authored Aug 30, 2024
1 parent 3e2ef14 commit 811b430
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
4 changes: 0 additions & 4 deletions builtin-functions/kphp-light/unsupported/crypto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
70 changes: 41 additions & 29 deletions runtime-light/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stdint.h>
#endif

#define K2_PLATFORM_HEADER_H_VERSION 6
#define K2_PLATFORM_HEADER_H_VERSION 7

// Always check that enum value is a valid value!

Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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).
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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`
Expand All @@ -183,15 +195,15 @@ 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()`
* There is no symmetric guarantee for `TimerStatusScheduled`.
*
* `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.
Expand All @@ -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:
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 811b430

Please sign in to comment.