|
| 1 | +/* |
| 2 | + * Copyright (C) 2024 Intel Corporation |
| 3 | + * |
| 4 | + * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. |
| 5 | + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +*/ |
| 7 | + |
| 8 | +#ifndef UMF_FILE_MEMORY_PROVIDER_H |
| 9 | +#define UMF_FILE_MEMORY_PROVIDER_H |
| 10 | + |
| 11 | +#include <umf/providers/provider_os_memory.h> |
| 12 | + |
| 13 | +#ifdef __cplusplus |
| 14 | +extern "C" { |
| 15 | +#endif |
| 16 | + |
| 17 | +/// @cond |
| 18 | +#define UMF_FILE_RESULTS_START_FROM 3000 |
| 19 | +/// @endcond |
| 20 | + |
| 21 | +/// @brief Memory provider settings struct |
| 22 | +typedef struct umf_file_memory_provider_params_t { |
| 23 | + /// a path to the file |
| 24 | + char *path; |
| 25 | + /// combination of 'umf_mem_protection_flags_t' flags |
| 26 | + unsigned protection; |
| 27 | + /// memory visibility mode |
| 28 | + umf_memory_visibility_t visibility; |
| 29 | +} umf_file_memory_provider_params_t; |
| 30 | + |
| 31 | +/// @brief File Memory Provider operation results |
| 32 | +typedef enum umf_file_memory_provider_native_error { |
| 33 | + UMF_FILE_RESULT_SUCCESS = UMF_FILE_RESULTS_START_FROM, ///< Success |
| 34 | + UMF_FILE_RESULT_ERROR_ALLOC_FAILED, ///< Memory allocation failed |
| 35 | + UMF_FILE_RESULT_ERROR_FREE_FAILED, ///< Memory deallocation failed |
| 36 | + UMF_FILE_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed |
| 37 | +} umf_file_memory_provider_native_error_t; |
| 38 | + |
| 39 | +umf_memory_provider_ops_t *umfFileMemoryProviderOps(void); |
| 40 | + |
| 41 | +/// @brief Create default params for the file memory provider |
| 42 | +static inline umf_file_memory_provider_params_t |
| 43 | +umfFileMemoryProviderParamsDefault(char *path) { |
| 44 | + umf_file_memory_provider_params_t params = { |
| 45 | + path, /* a path to the file */ |
| 46 | + UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */ |
| 47 | + UMF_MEM_MAP_PRIVATE, /* visibility mode */ |
| 48 | + }; |
| 49 | + |
| 50 | + return params; |
| 51 | +} |
| 52 | + |
| 53 | +#ifdef __cplusplus |
| 54 | +} |
| 55 | +#endif |
| 56 | + |
| 57 | +#endif /* UMF_FILE_MEMORY_PROVIDER_H */ |
0 commit comments