db_process.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * db_process.c
  17. *
  18. * This source file contains functions to create a child process and terminate
  19. * the running process. Child does not inherit any objects or memory from its
  20. * parent pricess. A Parent process may not modify the execution of its
  21. * children. It can wait for a child to exit using its handle. Also, parent and
  22. * child may communicate through I/O streams provided by the parent to the child
  23. * at creation.
  24. */
  25. #include "pal_defs.h"
  26. #include "pal_linux_defs.h"
  27. #include "pal.h"
  28. #include "pal_internal.h"
  29. #include "pal_linux.h"
  30. #include "pal_debug.h"
  31. #include "pal_error.h"
  32. #include "pal_security.h"
  33. #include "pal_rtld.h"
  34. #include "graphene.h"
  35. #include "graphene-ipc.h"
  36. #include "api.h"
  37. #include <linux/sched.h>
  38. #include <linux/types.h>
  39. typedef __kernel_pid_t pid_t;
  40. #include <asm/fcntl.h>
  41. #include <sys/socket.h>
  42. #include <asm/errno.h>
  43. #ifndef SEEK_SET
  44. # define SEEK_SET 0
  45. #endif
  46. static inline int create_process_handle (PAL_HANDLE * parent,
  47. PAL_HANDLE * child)
  48. {
  49. PAL_HANDLE phdl = NULL, chdl = NULL;
  50. int fds[6] = { -1, -1, -1, -1, -1, -1 };
  51. int ret;
  52. if (IS_ERR((ret = INLINE_SYSCALL(pipe2, 2, &fds[0], O_CLOEXEC))) ||
  53. IS_ERR((ret = INLINE_SYSCALL(pipe2, 2, &fds[2], O_CLOEXEC))) ||
  54. IS_ERR((ret = INLINE_SYSCALL(socketpair, 4, AF_UNIX,
  55. SOCK_STREAM|SOCK_CLOEXEC,
  56. 0, &fds[4])))) {
  57. ret = -PAL_ERROR_DENIED;
  58. goto out;
  59. }
  60. int proc_fds[2][3] = {
  61. { fds[0], fds[3], fds[4] },
  62. { fds[2], fds[1], fds[5] },
  63. };
  64. phdl = malloc(HANDLE_SIZE(process));
  65. if (!phdl) {
  66. ret = -PAL_ERROR_NOMEM;
  67. goto out;
  68. }
  69. SET_HANDLE_TYPE(phdl, process);
  70. HANDLE_HDR(phdl)->flags |= RFD(0)|WFD(1)|RFD(2)|WFD(2)|WRITABLE(1)|WRITABLE(2);
  71. phdl->process.stream_in = proc_fds[0][0];
  72. phdl->process.stream_out = proc_fds[0][1];
  73. phdl->process.cargo = proc_fds[0][2];
  74. phdl->process.pid = linux_state.pid;
  75. phdl->process.nonblocking = PAL_FALSE;
  76. chdl = malloc(HANDLE_SIZE(process));
  77. if (!chdl) {
  78. ret = -PAL_ERROR_NOMEM;
  79. goto out;
  80. }
  81. SET_HANDLE_TYPE(chdl, process);
  82. HANDLE_HDR(chdl)->flags |= RFD(0)|WFD(1)|RFD(2)|WFD(2)|WRITABLE(1)|WRITABLE(2);
  83. chdl->process.stream_in = proc_fds[1][0];
  84. chdl->process.stream_out = proc_fds[1][1];
  85. chdl->process.cargo = proc_fds[1][2];
  86. chdl->process.pid = 0; /* unknown yet */
  87. chdl->process.nonblocking = PAL_FALSE;
  88. *parent = phdl;
  89. *child = chdl;
  90. ret = 0;
  91. out:
  92. if (ret < 0) {
  93. if (phdl)
  94. _DkObjectClose(phdl);
  95. if (chdl)
  96. _DkObjectClose(chdl);
  97. for (int i = 0 ; i < 6 ; i++)
  98. if (fds[i] != -1)
  99. INLINE_SYSCALL(close, 1, fds[i]);
  100. }
  101. return ret;
  102. }
  103. struct proc_param {
  104. PAL_HANDLE parent;
  105. PAL_HANDLE exec;
  106. PAL_HANDLE manifest;
  107. const char ** argv;
  108. };
  109. struct proc_args {
  110. PAL_NUM parent_process_id;
  111. struct pal_sec pal_sec;
  112. #if PROFILING == 1
  113. unsigned long process_create_time;
  114. #endif
  115. unsigned long memory_quota;
  116. unsigned int parent_data_size;
  117. unsigned int exec_data_size;
  118. unsigned int manifest_data_size;
  119. };
  120. static int child_process (void * param)
  121. {
  122. struct proc_param * proc_param = param;
  123. int ret;
  124. ret = INLINE_SYSCALL(dup2, 2, proc_param->parent->process.stream_in,
  125. PROC_INIT_FD);
  126. if (IS_ERR(ret))
  127. goto failed;
  128. if (proc_param->parent)
  129. handle_set_cloexec(proc_param->parent, false);
  130. if (proc_param->exec)
  131. handle_set_cloexec(proc_param->exec, false);
  132. if (proc_param->manifest)
  133. handle_set_cloexec(proc_param->manifest, false);
  134. INLINE_SYSCALL(execve, 3, PAL_LOADER, proc_param->argv,
  135. linux_state.environ);
  136. failed:
  137. /* fail is it gets here */
  138. return -PAL_ERROR_DENIED;
  139. }
  140. int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
  141. {
  142. PAL_HANDLE exec = NULL;
  143. PAL_HANDLE parent_handle = NULL, child_handle = NULL;
  144. int ret;
  145. #if PROFILING == 1
  146. unsigned long before_create = _DkSystemTimeQuery();
  147. #endif
  148. /* step 1: open uri and check whether it is an executable */
  149. if (uri) {
  150. if ((ret = _DkStreamOpen(&exec, uri, PAL_ACCESS_RDONLY, 0, 0, 0)) < 0)
  151. return ret;
  152. if (check_elf_object(exec) < 0) {
  153. ret = -PAL_ERROR_INVAL;
  154. goto out;
  155. }
  156. /* If this process creation is for fork emulation,
  157. * map address of executable is already determined.
  158. * tell its address to forked process.
  159. */
  160. size_t len;
  161. const char * file_uri = "file:";
  162. if (exec_map && exec_map->l_name &&
  163. (len = strlen(uri)) >= 5 && !memcmp(uri, file_uri, 5) &&
  164. /* skip "file:"*/
  165. strlen(exec_map->l_name) == len - 5 &&
  166. /* + 1 for lasting * NUL */
  167. !memcmp(exec_map->l_name, uri + 5, len - 5 + 1))
  168. exec->file.map_start = (PAL_PTR)exec_map->l_map_start;
  169. }
  170. /* step 2: create parant and child process handle */
  171. struct proc_param param;
  172. ret = create_process_handle(&parent_handle, &child_handle);
  173. if (ret < 0)
  174. goto out;
  175. param.parent = parent_handle;
  176. param.exec = exec;
  177. param.manifest = pal_state.manifest_handle;
  178. /* step 3: compose process parameter */
  179. size_t parent_datasz = 0, exec_datasz = 0, manifest_datasz = 0;
  180. void * parent_data = NULL;
  181. void * exec_data = NULL;
  182. void * manifest_data = NULL;
  183. ret = handle_serialize(parent_handle, &parent_data);
  184. if (ret < 0)
  185. goto out;
  186. parent_datasz = (size_t)ret;
  187. if (exec) {
  188. ret = handle_serialize(exec, &exec_data);
  189. if (ret < 0) {
  190. free(parent_data);
  191. goto out;
  192. }
  193. exec_datasz = (size_t)ret;
  194. }
  195. if (pal_state.manifest_handle) {
  196. ret = handle_serialize(pal_state.manifest_handle, &manifest_data);
  197. if (ret < 0) {
  198. free(parent_data);
  199. free(exec_data);
  200. goto out;
  201. }
  202. manifest_datasz = (size_t)ret;
  203. }
  204. size_t datasz = parent_datasz + exec_datasz + manifest_datasz;
  205. struct proc_args * proc_args = __alloca(sizeof(struct proc_args) + datasz);
  206. proc_args->parent_process_id = linux_state.parent_process_id;
  207. memcpy(&proc_args->pal_sec, &pal_sec, sizeof(struct pal_sec));
  208. proc_args->pal_sec._dl_debug_state = NULL;
  209. proc_args->pal_sec._r_debug = NULL;
  210. proc_args->memory_quota = linux_state.memory_quota;
  211. void * data = (void *) (proc_args + 1);
  212. memcpy(data, parent_data, parent_datasz);
  213. data += (proc_args->parent_data_size = parent_datasz);
  214. free(parent_data);
  215. if (exec_data) {
  216. memcpy(data, exec_data, exec_datasz);
  217. data += (proc_args->exec_data_size = exec_datasz);
  218. free(exec_data);
  219. } else {
  220. proc_args->exec_data_size = 0;
  221. }
  222. if (manifest_data) {
  223. memcpy(data, manifest_data, manifest_datasz);
  224. data += (proc_args->manifest_data_size = manifest_datasz);
  225. free(manifest_data);
  226. } else {
  227. proc_args->manifest_data_size = 0;
  228. }
  229. /* step 4: create a child thread which will execve in the future */
  230. /* the first arguement must be the PAL */
  231. int argc = 0;
  232. if (args)
  233. for (; args[argc] ; argc++);
  234. param.argv = __alloca(sizeof(const char *) * (argc + 2));
  235. param.argv[0] = PAL_LOADER;
  236. if (args)
  237. memcpy(&param.argv[1], args, sizeof(const char *) * argc);
  238. param.argv[argc + 1] = NULL;
  239. #if PROFILING == 1
  240. proc_args->process_create_time = before_create;
  241. #endif
  242. ret = ARCH_VFORK();
  243. if (IS_ERR(ret)) {
  244. ret = -PAL_ERROR_DENIED;
  245. goto out;
  246. }
  247. if (!ret) {
  248. ret = child_process(&param);
  249. goto out; /* if child_process returned, there was a failure */
  250. }
  251. proc_args->pal_sec.process_id = ret;
  252. child_handle->process.pid = ret;
  253. /* step 4: send parameters over the process handle */
  254. ret = INLINE_SYSCALL(write, 3,
  255. child_handle->process.stream_out,
  256. proc_args,
  257. sizeof(struct proc_args) + datasz);
  258. if (IS_ERR(ret) || (size_t)ret < sizeof(struct proc_args) + datasz) {
  259. ret = -PAL_ERROR_DENIED;
  260. goto out;
  261. }
  262. *handle = child_handle;
  263. ret = 0;
  264. out:
  265. if (parent_handle)
  266. _DkObjectClose(parent_handle);
  267. if (exec)
  268. _DkObjectClose(exec);
  269. if (ret < 0) {
  270. if (child_handle)
  271. _DkObjectClose(child_handle);
  272. }
  273. return ret;
  274. }
  275. void init_child_process (PAL_HANDLE * parent_handle,
  276. PAL_HANDLE * exec_handle,
  277. PAL_HANDLE * manifest_handle)
  278. {
  279. int ret = 0;
  280. /* try to do a very large reading, so it doesn't have to be read for the
  281. second time */
  282. struct proc_args * proc_args = __alloca(sizeof(struct proc_args));
  283. struct proc_args * new_proc_args;
  284. int bytes = INLINE_SYSCALL(read, 3, PROC_INIT_FD, proc_args,
  285. sizeof(*proc_args));
  286. if (IS_ERR(bytes)) {
  287. if (ERRNO(bytes) != EBADF)
  288. INIT_FAIL(PAL_ERROR_DENIED, "communication fail with parent");
  289. /* in the first process */
  290. /* occupy PROC_INIT_FD so no one will use it */
  291. INLINE_SYSCALL(dup2, 2, 0, PROC_INIT_FD);
  292. return;
  293. }
  294. /* a child must have parent handle and an executable */
  295. if (!proc_args->parent_data_size)
  296. INIT_FAIL(PAL_ERROR_INVAL, "invalid process created");
  297. int datasz = proc_args->parent_data_size + proc_args->exec_data_size +
  298. proc_args->manifest_data_size;
  299. if (!datasz)
  300. goto no_data;
  301. new_proc_args = __alloca(sizeof(*proc_args) + datasz);
  302. memcpy(new_proc_args, proc_args, sizeof(*proc_args));
  303. proc_args = new_proc_args;
  304. void * data = (void *) (proc_args + 1);
  305. bytes = INLINE_SYSCALL(read, 3, PROC_INIT_FD, data, datasz);
  306. if (IS_ERR(bytes))
  307. INIT_FAIL(PAL_ERROR_DENIED, "communication fail with parent");
  308. /* now deserialize the parent_handle */
  309. PAL_HANDLE parent = NULL;
  310. ret = handle_deserialize(&parent, data, proc_args->parent_data_size);
  311. if (ret < 0)
  312. INIT_FAIL(-ret, "cannot deseilaize parent process handle");
  313. data += proc_args->parent_data_size;
  314. *parent_handle = parent;
  315. /* occupy PROC_INIT_FD so no one will use it */
  316. INLINE_SYSCALL(dup2, 2, 0, PROC_INIT_FD);
  317. /* deserialize the executable handle */
  318. if (proc_args->exec_data_size) {
  319. PAL_HANDLE exec = NULL;
  320. ret = handle_deserialize(&exec, data,
  321. proc_args->exec_data_size);
  322. if (ret < 0)
  323. INIT_FAIL(-ret, "cannot deserialize executable handle");
  324. data += proc_args->exec_data_size;
  325. *exec_handle = exec;
  326. }
  327. /* deserialize the manifest handle, if there is one */
  328. if (proc_args->manifest_data_size) {
  329. PAL_HANDLE manifest = NULL;
  330. ret = handle_deserialize(&manifest, data,
  331. proc_args->manifest_data_size);
  332. if (ret < 0)
  333. INIT_FAIL(-ret, "cannot deserialize manifest handle");
  334. data += proc_args->manifest_data_size;
  335. *manifest_handle = manifest;
  336. }
  337. no_data:
  338. linux_state.parent_process_id = proc_args->parent_process_id;
  339. linux_state.memory_quota = proc_args->memory_quota;
  340. #if PROFILING == 1
  341. pal_state.process_create_time = proc_args->process_create_time;
  342. #endif
  343. memcpy(&pal_sec, &proc_args->pal_sec, sizeof(struct pal_sec));
  344. }
  345. noreturn void _DkProcessExit (int exitcode)
  346. {
  347. INLINE_SYSCALL(exit_group, 1, exitcode);
  348. while (true) {
  349. /* nothing */;
  350. }
  351. }
  352. int ioctl_set_graphene (struct config_store * config, int ndefault,
  353. const struct graphene_user_policy * default_policies);
  354. static int set_graphene_task (const char * uri, int flags)
  355. {
  356. PAL_HANDLE handle = NULL;
  357. int ret;
  358. if ((ret = _DkStreamOpen(&handle, uri, PAL_ACCESS_RDONLY, 0, 0, 0)) < 0)
  359. return ret;
  360. PAL_STREAM_ATTR attr;
  361. if ((ret = _DkStreamAttributesQueryByHandle(handle, &attr)) < 0)
  362. goto out;
  363. void * addr = NULL;
  364. size_t size = attr.pending_size;
  365. if ((ret = _DkStreamMap(handle, &addr, PAL_PROT_READ, 0,
  366. ALLOC_ALIGNUP(size))) < 0)
  367. goto out;
  368. struct config_store sandbox_config;
  369. sandbox_config.raw_data = addr;
  370. sandbox_config.raw_size = size;
  371. sandbox_config.malloc = malloc;
  372. sandbox_config.free = free;
  373. if ((ret = read_config(&sandbox_config, NULL, NULL)) < 0)
  374. goto out_mem;
  375. struct graphene_user_policy policies[5], * p = policies;
  376. if (strpartcmp_static(uri, "file:")) {
  377. p->type = GRAPHENE_FS_PATH | GRAPHENE_FS_READ;
  378. p->value = &uri[5];
  379. p++;
  380. }
  381. if (flags & PAL_SANDBOX_PIPE) {
  382. p->type = GRAPHENE_UNIX_PREFIX;
  383. p->value = &pal_sec.pipe_prefix_id;
  384. p++;
  385. p->type = GRAPHENE_MCAST_PORT;
  386. p->value = &pal_sec.mcast_port;
  387. p++;
  388. }
  389. p->type = GRAPHENE_FS_PATH | GRAPHENE_FS_READ;
  390. p->value = "/proc/meminfo";
  391. p++;
  392. ret = ioctl_set_graphene(&sandbox_config, p - policies, policies);
  393. if (ret < 0)
  394. goto out_mem;
  395. pal_state.manifest = uri;
  396. _DkObjectClose(pal_state.manifest_handle);
  397. pal_state.manifest_handle = handle;
  398. free_config(&sandbox_config);
  399. out_mem:
  400. _DkStreamUnmap(sandbox_config.raw_data,
  401. ALLOC_ALIGNUP(sandbox_config.raw_size));
  402. out:
  403. _DkObjectClose(handle);
  404. return ret;
  405. }
  406. int _DkProcessSandboxCreate (const char * manifest, int flags)
  407. {
  408. return set_graphene_task(manifest, flags);
  409. }
  410. static int64_t proc_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
  411. void * buffer)
  412. {
  413. if (offset)
  414. return -PAL_ERROR_INVAL;
  415. int64_t bytes = INLINE_SYSCALL(read, 3, handle->process.stream_in, buffer,
  416. count);
  417. if (IS_ERR(bytes))
  418. switch(ERRNO(bytes)) {
  419. case EWOULDBLOCK:
  420. return -PAL_ERROR_TRYAGAIN;
  421. case EINTR:
  422. return -PAL_ERROR_INTERRUPTED;
  423. default:
  424. return -PAL_ERROR_DENIED;
  425. }
  426. return bytes;
  427. }
  428. static int64_t proc_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
  429. const void * buffer)
  430. {
  431. if (offset)
  432. return -PAL_ERROR_INVAL;
  433. int64_t bytes = INLINE_SYSCALL(write, 3, handle->process.stream_out, buffer,
  434. count);
  435. if (IS_ERR(bytes))
  436. switch(ERRNO(bytes)) {
  437. case EWOULDBLOCK:
  438. HANDLE_HDR(handle)->flags &= ~WRITABLE(1);
  439. return -PAL_ERROR_TRYAGAIN;
  440. case EINTR:
  441. return -PAL_ERROR_INTERRUPTED;
  442. default:
  443. return -PAL_ERROR_DENIED;
  444. }
  445. assert(!IS_ERR(bytes));
  446. if ((size_t)bytes == count)
  447. HANDLE_HDR(handle)->flags |= WRITABLE(1);
  448. else
  449. HANDLE_HDR(handle)->flags &= ~WRITABLE(1);
  450. return bytes;
  451. }
  452. static int proc_close (PAL_HANDLE handle)
  453. {
  454. if (handle->process.stream_in != PAL_IDX_POISON) {
  455. INLINE_SYSCALL(close, 1, handle->process.stream_in);
  456. handle->process.stream_in = PAL_IDX_POISON;
  457. }
  458. if (handle->process.stream_out != PAL_IDX_POISON) {
  459. INLINE_SYSCALL(close, 1, handle->process.stream_out);
  460. handle->process.stream_out = PAL_IDX_POISON;
  461. }
  462. if (handle->process.cargo != PAL_IDX_POISON) {
  463. INLINE_SYSCALL(close, 1, handle->process.cargo);
  464. handle->process.cargo = PAL_IDX_POISON;
  465. }
  466. return 0;
  467. }
  468. static int proc_delete (PAL_HANDLE handle, int access)
  469. {
  470. int shutdown;
  471. switch (access) {
  472. case 0:
  473. shutdown = SHUT_RDWR;
  474. break;
  475. case PAL_DELETE_RD:
  476. shutdown = SHUT_RD;
  477. break;
  478. case PAL_DELETE_WR:
  479. shutdown = SHUT_WR;
  480. break;
  481. default:
  482. return -PAL_ERROR_INVAL;
  483. }
  484. if (access != PAL_DELETE_WR &&
  485. handle->process.stream_in != PAL_IDX_POISON) {
  486. INLINE_SYSCALL(close, 1, handle->process.stream_in);
  487. handle->process.stream_in = PAL_IDX_POISON;
  488. }
  489. if (access != PAL_DELETE_RD &&
  490. handle->process.stream_out != PAL_IDX_POISON) {
  491. INLINE_SYSCALL(close, 1, handle->process.stream_out);
  492. handle->process.stream_out = PAL_IDX_POISON;
  493. }
  494. if (handle->process.cargo != PAL_IDX_POISON)
  495. INLINE_SYSCALL(shutdown, 2, handle->process.cargo, shutdown);
  496. return 0;
  497. }
  498. #ifndef FIONREAD
  499. # define FIONREAD 0x541B
  500. #endif
  501. static int proc_attrquerybyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
  502. {
  503. int ret, val;
  504. if (handle->process.stream_in == PAL_IDX_POISON)
  505. return -PAL_ERROR_BADHANDLE;
  506. ret = INLINE_SYSCALL(ioctl, 3, handle->process.stream_in, FIONREAD, &val);
  507. if (IS_ERR(ret))
  508. return unix_to_pal_error(ERRNO(ret));
  509. attr->handle_type = pal_type_process;
  510. attr->nonblocking = handle->process.nonblocking;
  511. attr->disconnected = HANDLE_HDR(handle)->flags & (ERROR(0)|ERROR(1));
  512. attr->readable = !!val;
  513. attr->writable = HANDLE_HDR(handle)->flags & WRITABLE(1);
  514. attr->runnable = PAL_FALSE;
  515. attr->pending_size = val;
  516. return 0;
  517. }
  518. static int proc_attrsetbyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
  519. {
  520. if (handle->process.stream_in == PAL_IDX_POISON)
  521. return -PAL_ERROR_BADHANDLE;
  522. int ret;
  523. if (attr->nonblocking != handle->process.nonblocking) {
  524. ret = INLINE_SYSCALL(fcntl, 3, handle->process.stream_in, F_SETFL,
  525. handle->process.nonblocking ? O_NONBLOCK : 0);
  526. if (IS_ERR(ret))
  527. return unix_to_pal_error(ERRNO(ret));
  528. handle->process.nonblocking = attr->nonblocking;
  529. }
  530. return 0;
  531. }
  532. struct handle_ops proc_ops = {
  533. .read = &proc_read,
  534. .write = &proc_write,
  535. .close = &proc_close,
  536. .delete = &proc_delete,
  537. .attrquerybyhdl = &proc_attrquerybyhdl,
  538. .attrsetbyhdl = &proc_attrsetbyhdl,
  539. };