Implement stat and getentropy for sgx with ocall to run tensorflow (#436)

This commit is contained in:
Wenyong Huang 2020-10-30 12:36:00 +08:00 committed by GitHub
parent ed94b7dcc4
commit 667282eea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 2 deletions

View File

@ -49,9 +49,11 @@ int ocall_closedir(int *p_ret, void *dirp);
/** DIR end **/
/** stat **/
int ocall_stat(int *p_ret, const char *pathname,
void *buf, unsigned int buf_len);
int ocall_fstat(int *p_ret, int fd, void *buf, unsigned int buf_len);
int ocall_fstatat(int *p_ret, int dirfd, const char *pathname, void *buf,
unsigned int buf_len, int flags);
int ocall_fstatat(int *p_ret, int dirfd, const char *pathname,
void *buf, unsigned int buf_len, int flags);
/** stat end **/
/** link **/
@ -87,6 +89,7 @@ int ocall_getopt(int *p_ret, int argc, char *argv_buf,
unsigned int argv_buf_len, const char *optstring);
int ocall_getrandom(ssize_t *p_ret, void *buf, size_t buflen,
unsigned int flags);
int ocall_getentropy(int *p_ret, void *buffer, size_t length);
int ocall_sched_yield(int *p_ret);
/** struct iovec **/
@ -449,6 +452,25 @@ int ftruncate(int fd, off_t length)
return ret;
}
int stat(const char *pathname, struct stat *statbuf)
{
int ret;
if (statbuf == NULL)
return -1;
if (ocall_stat(&ret, pathname,
(void *)statbuf,
sizeof(struct stat)) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
return -1;
}
if (ret == -1)
errno = get_errno();
return ret;
}
int fstat(int fd, struct stat *statbuf)
{
int ret;
@ -822,6 +844,19 @@ ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
return ret;
}
int getentropy(void *buffer, size_t length)
{
int ret;
if (ocall_getentropy(&ret, buffer, length) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
return -1;
}
if (ret == -1)
errno = get_errno();
return ret;
}
int get_errno(void)
{
int ret;

View File

@ -183,6 +183,7 @@ ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
off_t lseek(int fd, off_t offset, int whence);
int ftruncate(int fd, off_t length);
int stat(const char *pathname, struct stat *statbuf);
int fstat(int fd, struct stat *statbuf);
int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
int flags);
@ -218,6 +219,7 @@ int getopt(int argc, char * const argv[],
int sched_yield(void);
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
int getentropy(void *buffer, size_t length);
int get_errno(void);

View File

@ -30,6 +30,9 @@ enclave {
long ocall_telldir([user_check]void *dirp);
int ocall_closedir([user_check]void *dirp);
int ocall_stat([in, string]const char *pathname,
[out, size=buf_len]void *buf,
unsigned int buf_len);
int ocall_fstat(int fd, [out, size=buf_len]void *buf,
unsigned int buf_len);
int ocall_fstatat(int dirfd, [in, string]const char *pathname,
@ -76,6 +79,7 @@ enclave {
[in, string]const char *optstring);
ssize_t ocall_getrandom([out, size=buflen]void *buf, size_t buflen,
unsigned int flags);
int ocall_getentropy([out, size=length]void *buffer, size_t length);
ssize_t ocall_readv(int fd,
[in, out, size=buf_size]char *iov_buf,
unsigned int buf_size, int iovcnt,

View File

@ -130,6 +130,12 @@ int ocall_closedir(void* dirp)
return -1;
}
int ocall_stat(const char *pathname,
void *buf, unsigned int buf_len)
{
return stat(pathname, (struct stat *)buf);
}
int ocall_fstat(int fd, void *buf, unsigned int buf_len)
{
return fstat(fd, (struct stat *)buf);
@ -277,6 +283,11 @@ ssize_t ocall_getrandom(void *buf, size_t buflen, unsigned int flags)
return getrandom(buf, buflen, flags);
}
int ocall_getentropy(void *buffer, size_t length)
{
return getentropy(buffer, length);
}
int ocall_sched_yield()
{
return sched_yield();