mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Add @(no_sanitize_memory) proc attribute with MSan additions to base:sanitizer
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
#+no-instrumentation
|
||||||
|
package sanitizer
|
||||||
|
|
||||||
|
@(private="file")
|
||||||
|
MSAN_ENABLED :: .Memory in ODIN_SANITIZER_FLAGS
|
||||||
|
|
||||||
|
@(private="file")
|
||||||
|
@(default_calling_convention="system")
|
||||||
|
foreign {
|
||||||
|
__msan_unpoison :: proc(addr: rawptr, size: uint) ---
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Marks a slice as fully initialized.
|
||||||
|
|
||||||
|
Code instrumented with `-sanitize:memory` will be permitted to access any
|
||||||
|
address within the slice as if it had already been initialized.
|
||||||
|
|
||||||
|
When msan is not enabled this procedure does nothing.
|
||||||
|
*/
|
||||||
|
memory_unpoison_slice :: proc "contextless" (region: $T/[]$E) {
|
||||||
|
when MSAN_ENABLED {
|
||||||
|
__msan_unpoison(raw_data(region), size_of(E) * len(region))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Marks a pointer as fully initialized.
|
||||||
|
|
||||||
|
Code instrumented with `-sanitize:memory` will be permitted to access memory
|
||||||
|
within the region the pointer points to as if it had already been initialized.
|
||||||
|
|
||||||
|
When msan is not enabled this procedure does nothing.
|
||||||
|
*/
|
||||||
|
memory_unpoison_ptr :: proc "contextless" (ptr: ^$T) {
|
||||||
|
when MSAN_ENABLED {
|
||||||
|
__msan_unpoison(ptr, size_of(T))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Marks the region covering `[ptr, ptr+len)` as fully initialized.
|
||||||
|
|
||||||
|
Code instrumented with `-sanitize:memory` will be permitted to access memory
|
||||||
|
within this range as if it had already been initialized.
|
||||||
|
|
||||||
|
When msan is not enabled this procedure does nothing.
|
||||||
|
*/
|
||||||
|
memory_unpoison_rawptr :: proc "contextless" (ptr: rawptr, len: int) {
|
||||||
|
when MSAN_ENABLED {
|
||||||
|
__msan_unpoison(ptr, uint(len))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Marks the region covering `[ptr, ptr+len)` as fully initialized.
|
||||||
|
|
||||||
|
Code instrumented with `-sanitize:memory` will be permitted to access memory
|
||||||
|
within this range as if it had already been initialized.
|
||||||
|
|
||||||
|
When msan is not enabled this procedure does nothing.
|
||||||
|
*/
|
||||||
|
memory_unpoison_rawptr_uint :: proc "contextless" (ptr: rawptr, len: uint) {
|
||||||
|
when MSAN_ENABLED {
|
||||||
|
__msan_unpoison(ptr, len)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memory_unpoison :: proc {
|
||||||
|
memory_unpoison_slice,
|
||||||
|
memory_unpoison_ptr,
|
||||||
|
memory_unpoison_rawptr,
|
||||||
|
memory_unpoison_rawptr_uint,
|
||||||
|
}
|
||||||
@@ -1370,6 +1370,7 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
|||||||
e->Procedure.has_instrumentation = has_instrumentation;
|
e->Procedure.has_instrumentation = has_instrumentation;
|
||||||
|
|
||||||
e->Procedure.no_sanitize_address = ac.no_sanitize_address;
|
e->Procedure.no_sanitize_address = ac.no_sanitize_address;
|
||||||
|
e->Procedure.no_sanitize_memory = ac.no_sanitize_memory;
|
||||||
|
|
||||||
e->deprecated_message = ac.deprecated_message;
|
e->deprecated_message = ac.deprecated_message;
|
||||||
e->warning_message = ac.warning_message;
|
e->warning_message = ac.warning_message;
|
||||||
|
|||||||
@@ -3776,6 +3776,12 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
|
|||||||
}
|
}
|
||||||
ac->no_sanitize_address = true;
|
ac->no_sanitize_address = true;
|
||||||
return true;
|
return true;
|
||||||
|
} else if (name == "no_sanitize_memory") {
|
||||||
|
if (value != nullptr) {
|
||||||
|
error(value, "'%.*s' expects no parameter", LIT(name));
|
||||||
|
}
|
||||||
|
ac->no_sanitize_memory = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ struct AttributeContext {
|
|||||||
bool instrumentation_enter : 1;
|
bool instrumentation_enter : 1;
|
||||||
bool instrumentation_exit : 1;
|
bool instrumentation_exit : 1;
|
||||||
bool no_sanitize_address : 1;
|
bool no_sanitize_address : 1;
|
||||||
|
bool no_sanitize_memory : 1;
|
||||||
bool rodata : 1;
|
bool rodata : 1;
|
||||||
bool ignore_duplicates : 1;
|
bool ignore_duplicates : 1;
|
||||||
u32 optimization_mode; // ProcedureOptimizationMode
|
u32 optimization_mode; // ProcedureOptimizationMode
|
||||||
|
|||||||
@@ -263,6 +263,7 @@ struct Entity {
|
|||||||
bool uses_branch_location : 1;
|
bool uses_branch_location : 1;
|
||||||
bool is_anonymous : 1;
|
bool is_anonymous : 1;
|
||||||
bool no_sanitize_address : 1;
|
bool no_sanitize_address : 1;
|
||||||
|
bool no_sanitize_memory : 1;
|
||||||
} Procedure;
|
} Procedure;
|
||||||
struct {
|
struct {
|
||||||
Array<Entity *> entities;
|
Array<Entity *> entities;
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
|
|||||||
if (build_context.sanitizer_flags & SanitizerFlag_Address && !entity->Procedure.no_sanitize_address) {
|
if (build_context.sanitizer_flags & SanitizerFlag_Address && !entity->Procedure.no_sanitize_address) {
|
||||||
lb_add_attribute_to_proc(m, p->value, "sanitize_address");
|
lb_add_attribute_to_proc(m, p->value, "sanitize_address");
|
||||||
}
|
}
|
||||||
if (build_context.sanitizer_flags & SanitizerFlag_Memory) {
|
if (build_context.sanitizer_flags & SanitizerFlag_Memory && !entity->Procedure.no_sanitize_memory) {
|
||||||
lb_add_attribute_to_proc(m, p->value, "sanitize_memory");
|
lb_add_attribute_to_proc(m, p->value, "sanitize_memory");
|
||||||
}
|
}
|
||||||
if (build_context.sanitizer_flags & SanitizerFlag_Thread) {
|
if (build_context.sanitizer_flags & SanitizerFlag_Thread) {
|
||||||
|
|||||||
Reference in New Issue
Block a user