Last active
April 4, 2023 09:09
-
-
Save kbagher/e20a46773a772ec57c5022ef40d01f24 to your computer and use it in GitHub Desktop.
Passing callback function pointer to an enclave (Intel SGX)
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
void CallMe(int x) { | |
printf("Num %d\n",x); | |
} | |
int main() { | |
/* Setup enclave */ | |
sgx_enclave_id_t eid; | |
sgx_status_t ret; | |
sgx_launch_token_t token = { 0 }; | |
int token_updated = 0; | |
ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, | |
&token_updated, &eid, NULL); | |
if (ret != SGX_SUCCESS) { | |
cout << "sgx_create_enclave failed: 0x" << std::hex << ret << endl; | |
return 1; | |
} | |
FunctionPointer ptr = { &CallMe }; | |
ecall_pass_func(eid, &ptr); | |
sgx_destroy_enclave(eid); | |
} |
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
void ecall_pass_func(FunctionPointer *ptr){ | |
ptr->ptr(10); | |
} |
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
enclave { | |
include "user_type.h" | |
trusted { | |
public void ecall_pass_func([user_check] FunctionPointer *ptr); | |
}; | |
untrusted { | |
}; | |
}; |
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
struct FunctionPointer{ | |
void (*ptr)(int); | |
}; | |
typedef struct FunctionPointer FunctionPointer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This approach won’t work if you pass class member function.