Native Client‎ > ‎

blocking operation restriction

NAME

NaClSyscallRestrict

SYNOPSIS

#include <nacl/restrict.h>

ssize_t NaClSyscallRestrict(int op, size_t desc_count, int *desc);

DESCRIPTION

A thread may invoke NaClSyscallRestrict to prevent itself from performing some potentially slow or blocking system calls.  The list of system call affected by NaClSyscallRestrict is currently hard-wired and cannot be changed.  The intention is that the Pepper upcall handler thread can prevent itself from performing blocking operations, e.g., reading a file that might involve fetching file data over a network, because the user's profile is stored on a network file system.  This is important because the Pepper upcall handler thread, if blocked, will cause the JavaScript thread to become unresponsive, and the browser's responsiveness suffers.  The op argument of NaClSyscallRestrict may be one of:
    • NACL_RESTRICT_ENABLE:  Enable blocking operation restriction enforcement.  The desc_count and desc parameters are ignored.
    • NACL_RESTRICT_DISABLE:  Disable blocking operation enforcement.  The desc_count and desc parameters are ignored.
    • NACL_RESTRICT_SET:  Sets the list of permitted descriptors to the provided list.
    • NACL_RESTRICT_GET:  The current list of permitted descriptors is written to desc, up to desc_count, and the number of written descriptors is returned (min of actual current list and desc_count, so only when returned value is less than desc_count can the caller be sure that the entire list of permitted descriptors have been retrieved).
    • NACL_RESTRICT_ADD:  Adds the provided descriptors to the current list of descriptors for which the invoking thread is permitted to make potentially blocking system calls.  Returns the size of the permitted descriptor list for the thread after the add operation.
    • NACL_RESTRICT_REMOVE:  Removes the provided descriptors from list of permitted descriptors.  Returns the size of the permitted descriptor list for the thread after the remove operation.
Threads are created with blocking operation restrictions disabled, and an empty list of permitted descriptors.  The permitted descriptor list are not references to descriptors:  if a permitted descriptor is closed and another duped into the same open descriptor table slot, operations on the new descriptor would also be permitted.  It is the responsibility of the application program to properly maintain the list of permitted descriptors.

When potentially blocking/slow system calls are made on a descriptor not on the permitted list while blocking operation restriction is enabled, the system call returns -1 with errno set to EWOULDBLOCK.  This occurs even if the system call would have returned immediately (e.g., data is available, lock not held) were blocking operation restriction not in force.

SEE ALSO
open, read, write, fstat, imc_accept, imc_connect, imc_sendmsg, imc_recvmsg, pthread_mutex_lock, pthread_cond_wait, pthread_sem_wait

Comments