-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AOT module validation to ensure memory constraints are met
- Loading branch information
Showing
3 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2019 Intel Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#include "aot_validator.h" | ||
|
||
static void | ||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string) | ||
{ | ||
if (error_buf != NULL) { | ||
snprintf(error_buf, error_buf_size, | ||
"AOT module load failed: from validator. %s", string); | ||
} | ||
} | ||
|
||
static bool | ||
aot_memory_info_validate(const AOTModule *module, char *error_buf, | ||
uint32 error_buf_size) | ||
{ | ||
if (module->import_memory_count > 0) { | ||
set_error_buf(error_buf, error_buf_size, | ||
"import memory is not supported"); | ||
return false; | ||
} | ||
|
||
if (module->memory_count < 1) { | ||
set_error_buf(error_buf, error_buf_size, | ||
"there should be >=1 memory in one aot module"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool | ||
aot_module_validate(const AOTModule *module, char *error_buf, | ||
uint32 error_buf_size) | ||
{ | ||
if (!aot_memory_info_validate(module, error_buf, error_buf_size)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (C) 2019 Intel Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#ifndef _AOT_VALIDATOR_H_ | ||
#define _AOT_VALIDATOR_H_ | ||
|
||
#include "aot_runtime.h" | ||
|
||
bool | ||
aot_module_validate(const AOTModule *module, char *error_buf, | ||
uint32 error_buf_size); | ||
|
||
#endif /* _AOT_VALIDATOR_H_ */ |