<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Hello Svart, in Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Read-file-content-from-Enclave-with-OCall/m-p/1124655#M1679</link>
    <description>&lt;P&gt;Hello Svart,&lt;/P&gt;

&lt;P&gt;In the above program, the "read_IMA_file" trusted function is called with pointer variable(OUT pointer) of type character.Here we are passing the pointer variable without&lt;BR /&gt;
	any memory allocation.&lt;BR /&gt;
	"read_IMA_file" initiate a OCall that allocate memory and do "Copy" operation.Now the allocated memory is valid within the untrusted region. So we are getting expected result&lt;BR /&gt;
	for the "cout&amp;lt;&amp;lt;content" as "123456789".&lt;/P&gt;

&lt;P&gt;Since there is no trusted memory allocated for "content"(before calling Ocall), no copy back operation happens in "OUT" pointer during Ocall returns.&lt;BR /&gt;
	So "buf" doesn't contain any valid data while doing "print(buf)"&amp;nbsp; after Ocall returns in trusted region.&lt;/P&gt;

&lt;P&gt;Please try with valid OUT pointer to character buffer(with some memory allocation)&amp;nbsp;or IN and OUT pointer to String buffer.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	R.Prabu&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2017 17:41:25 GMT</pubDate>
    <dc:creator>Prabu_R_Intel</dc:creator>
    <dc:date>2017-01-04T17:41:25Z</dc:date>
    <item>
      <title>Read file content from Enclave with OCall</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Read-file-content-from-Enclave-with-OCall/m-p/1124654#M1678</link>
      <description>&lt;P&gt;I'm trying to read the content of a file from an enclave using OCalls.&lt;/P&gt;

&lt;P&gt;This is what I got so far:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;//enclave.edl
untrusted {
        void ocall_print_string([in, string] const char *str);
        void ocall_read_IMA_file([in, string] const char *filename, [out] char *buf, [out] int *size);
};&lt;/PRE&gt;

&lt;PRE class="brush:cpp;"&gt;//enclave.cpp

void printf(const char *fmt, ...) {
	ocall_print_string(fmt);
}


void read_IMA_file(const char *filename, char *buf, int *size) {
	ocall_read_IMA_file(filename, buf, size);

	printf(buf);
}

//whereas the read_IMA_file function is called with
char *buf;
int size;
read_IMA_file("test.txt", buf, &amp;amp;size);&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;// implementation of ocall functions
void ocall_print_string(const char *str) {
	printf("%s\n", str);
}


void ocall_read_IMA_file(const char *filename, char *content, int *size) {
	content = (char*) malloc(sizeof(char) * 10);
	memset(content, '\0', sizeof(char) *10);
	char tmp[] = "1234567890";
	copy(&amp;amp;tmp[0], &amp;amp;tmp[9], content);

	cout &amp;lt;&amp;lt; content &amp;lt;&amp;lt; endl;
}&lt;/PRE&gt;

&lt;P&gt;But the result I receive is the following:&lt;/P&gt;

&lt;P&gt;123456789&lt;BR /&gt;
	(null)&lt;/P&gt;

&lt;P&gt;I'm not sure what I'm doing wrong!?&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 14:24:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Read-file-content-from-Enclave-with-OCall/m-p/1124654#M1678</guid>
      <dc:creator>Svart_K_</dc:creator>
      <dc:date>2017-01-03T14:24:26Z</dc:date>
    </item>
    <item>
      <title>Hello Svart,</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Read-file-content-from-Enclave-with-OCall/m-p/1124655#M1679</link>
      <description>&lt;P&gt;Hello Svart,&lt;/P&gt;

&lt;P&gt;In the above program, the "read_IMA_file" trusted function is called with pointer variable(OUT pointer) of type character.Here we are passing the pointer variable without&lt;BR /&gt;
	any memory allocation.&lt;BR /&gt;
	"read_IMA_file" initiate a OCall that allocate memory and do "Copy" operation.Now the allocated memory is valid within the untrusted region. So we are getting expected result&lt;BR /&gt;
	for the "cout&amp;lt;&amp;lt;content" as "123456789".&lt;/P&gt;

&lt;P&gt;Since there is no trusted memory allocated for "content"(before calling Ocall), no copy back operation happens in "OUT" pointer during Ocall returns.&lt;BR /&gt;
	So "buf" doesn't contain any valid data while doing "print(buf)"&amp;nbsp; after Ocall returns in trusted region.&lt;/P&gt;

&lt;P&gt;Please try with valid OUT pointer to character buffer(with some memory allocation)&amp;nbsp;or IN and OUT pointer to String buffer.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	R.Prabu&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 17:41:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Read-file-content-from-Enclave-with-OCall/m-p/1124655#M1679</guid>
      <dc:creator>Prabu_R_Intel</dc:creator>
      <dc:date>2017-01-04T17:41:25Z</dc:date>
    </item>
  </channel>
</rss>

