intel / linux-sgx

Intel SGX for Linux*
https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/linux-overview.html
Other
1.33k stars 543 forks source link

sgx_emmt shows 0KB #237

Open gmatesunny opened 6 years ago

gmatesunny commented 6 years ago

Related to closed issue #136 I have a mbed-sgx server(multi-threaded) that sets up the ssl context inside enclave and the infinite loop to accept connection runs at the app and does some analysis inside the enclave. It stops on SIGINT signal.

Related Server code snippet.

    std::signal(SIGINT, exitGraceful);
    do {

        std::this_thread::sleep_for (std::chrono::seconds(1));
        if (quit.load()) {
            cerr << "APP: Ctrl-C/SIGINT passed.\n" << endl;
            break;
        }
     mbedtls_net_accept(&listen_fd, &client_fd, NULL, 0, NULL);
   } while(true);
    mbedtls_printf("APP: About to exit\n");
    sgx_destroy_enclave(eid);
    return (ret);
}

So I wanted to calculate max stack size and heap size. I did this: Terminal 1: run my server Terminal 2: run sgx-gdb

enable sgx_emmt
attach 3975(pid of my server )
continue &

Terminal 3: I send a request to the server and the server send reponse.

Now, on Terminal 1, I press Ctrl+C, nothing happens and the server does not exits but gdb on terminal 1 prints:

Thread 1 "osn_server" received signal SIGINT, Interrupt.
0x00007f4ffbc7fc1d in nanosleep () at ../sysdeps/unix/syscall-template.S:84
84  in ../sysdeps/unix/syscall-template.S

After that on gdb I do: signal 2 and now my server terminates and gdb prints

Enclave: "/home/roshan/thesis/osn_server/sgx/enclave_enclave/enclave.signed.so"
  [Peak stack used]: 0 KB
  [Can't get peak heap used]: You may use version script to control symbol export. Please export 'g_peak_heap_used' in your version script.
remove-symbol-file -a 139978543850752
[Inferior 1 (process 3975) exited normally]

If I do not do [Terminal 1, I press Ctrl+C] and directly write signal 2 in gdb, nothing happens to the server and it continues to run and gdb prints: Cannot execute this command without a live selected thread.

Why the stack size prints 0KB and the how I get peak heap used. Am I doing the things in the correct way?

PS: I am using SIM mode.

llly commented 6 years ago

sgx_destroy_enclave must be called to get stack and heap usage. It seem that the server is terminated without destroy the enclave. You can add a signal handler to destroy the enclaves that you want to measure when SIGINT received.

gmatesunny commented 6 years ago

I have added signal handler as well as sgx_destroy_enclave call.

std::signal(SIGINT, exitGraceful); sgx_destroy_enclave(eid);