io-wrapper.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /* io.defs wrapper code.
  2. Copyright (C) 2008 Free Software Foundation, Inc.
  3. Written by FlÃvio Cruz <flaviocruz@gmail.com>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include <mach/boolean.h>
  16. #include <mach/kern_return.h>
  17. #include <mach/message.h>
  18. #include <mach/mig_errors.h>
  19. #include <mach/mig_support.h>
  20. #include <mach/std_types.h>
  21. #include <mach/mach_types.h>
  22. #include <device/device_types.h>
  23. #include <device/net_status.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/statfs.h>
  27. #include <sys/resource.h>
  28. #include <sys/utsname.h>
  29. #include <hurd/hurd_types.h>
  30. #include <stdio.h>
  31. #include <assert.h>
  32. #include "io-wrapper.h"
  33. /* this is NULL initialized */
  34. static void *routines[_NUMBER_OF_ROUTINES];
  35. /* function wrappers follows... */
  36. /* io write */
  37. typedef kern_return_t (*io_write_type) (io_t,
  38. data_t, mach_msg_type_number_t,
  39. int, vm_size_t *);
  40. kern_return_t
  41. lisp_S_io_write (io_t io_object,
  42. data_t data,
  43. mach_msg_type_number_t dataCnt,
  44. loff_t offset, vm_size_t * amount)
  45. {
  46. if (routines[IO_WRITE] == NULL)
  47. {
  48. return EOPNOTSUPP;
  49. }
  50. io_write_type write_routine = routines[IO_WRITE];
  51. return write_routine (io_object, data, dataCnt, (int)offset, amount);
  52. }
  53. /* io read */
  54. typedef kern_return_t (*io_read_type) (io_t,
  55. data_t *, mach_msg_type_number_t *,
  56. int, vm_size_t);
  57. kern_return_t
  58. lisp_S_io_read (io_t io_object,
  59. data_t * data,
  60. mach_msg_type_number_t * dataCnt,
  61. loff_t offset, vm_size_t amount)
  62. {
  63. if (routines[IO_READ] == NULL)
  64. {
  65. return EOPNOTSUPP;
  66. }
  67. io_read_type read_routine = routines[IO_READ];
  68. return read_routine (io_object, data, dataCnt, (int)offset, amount);
  69. }
  70. /* io seek */
  71. typedef kern_return_t (*io_seek_type) (io_t, int, int, int *);
  72. kern_return_t
  73. lisp_S_io_seek (io_t io_object, loff_t offset, int whence, loff_t * newp)
  74. {
  75. if (routines[IO_SEEK] == NULL)
  76. {
  77. return EOPNOTSUPP;
  78. }
  79. io_seek_type seek_routine = routines[IO_SEEK];
  80. return seek_routine (io_object, (int)offset, whence, (int *)newp);
  81. }
  82. /* io readable */
  83. typedef kern_return_t (*io_readable_type) (io_t, vm_size_t *);
  84. kern_return_t
  85. lisp_S_io_readable (io_t io_object, vm_size_t * amount)
  86. {
  87. if (routines[IO_READABLE] == NULL)
  88. {
  89. return EOPNOTSUPP;
  90. }
  91. io_readable_type readable_routine = routines[IO_READABLE];
  92. return readable_routine (io_object, amount);
  93. }
  94. /* io set all openmodes */
  95. typedef kern_return_t (*io_set_all_openmodes_type) (io_t, int);
  96. kern_return_t
  97. lisp_S_io_set_all_openmodes (io_t io_object, int newbits)
  98. {
  99. if (routines[IO_SET_ALL_OPENMODES] == NULL)
  100. {
  101. return EOPNOTSUPP;
  102. }
  103. io_set_all_openmodes_type set_all_openmodes_routine =
  104. routines[IO_SET_ALL_OPENMODES];
  105. return set_all_openmodes_routine (io_object, newbits);
  106. }
  107. /* io get openmodes */
  108. typedef kern_return_t (*io_get_openmodes_type) (io_t, int *);
  109. kern_return_t
  110. lisp_S_io_get_openmodes (io_t io_object, int *bits)
  111. {
  112. if (routines[IO_GET_OPENMODES] == NULL)
  113. {
  114. return EOPNOTSUPP;
  115. }
  116. io_get_openmodes_type get_openmodes_routine = routines[IO_GET_OPENMODES];
  117. return get_openmodes_routine (io_object, bits);
  118. }
  119. /* io set some openmodes */
  120. typedef kern_return_t (*io_set_some_openmodes_type) (io_t, int);
  121. kern_return_t
  122. lisp_S_io_set_some_openmodes (io_t io_object, int bits_to_set)
  123. {
  124. if (routines[IO_SET_SOME_OPENMODES] == NULL)
  125. {
  126. return EOPNOTSUPP;
  127. }
  128. io_set_some_openmodes_type set_some_openmodes_routine =
  129. routines[IO_SET_SOME_OPENMODES];
  130. return set_some_openmodes_routine (io_object, bits_to_set);
  131. }
  132. /* io clear some openmodes */
  133. typedef kern_return_t (*io_clear_some_openmodes_type) (io_t, int);
  134. kern_return_t
  135. lisp_S_io_clear_some_openmodes (io_t io_object, int bits_to_clear)
  136. {
  137. if (routines[IO_CLEAR_SOME_OPENMODES] == NULL)
  138. {
  139. return EOPNOTSUPP;
  140. }
  141. io_clear_some_openmodes_type clear_some_openmodes_routine =
  142. routines[IO_CLEAR_SOME_OPENMODES];
  143. return clear_some_openmodes_routine (io_object, bits_to_clear);
  144. }
  145. /* io async */
  146. typedef kern_return_t (*io_async_type) (io_t, mach_port_t,
  147. mach_port_t *,
  148. mach_msg_type_name_t *);
  149. kern_return_t
  150. lisp_S_io_async (io_t io_object,
  151. mach_port_t notify_port,
  152. mach_port_t * async_id_port,
  153. mach_msg_type_name_t * async_id_portPoly)
  154. {
  155. if (routines[IO_ASYNC] == NULL)
  156. {
  157. return EOPNOTSUPP;
  158. }
  159. io_async_type async_routine = routines[IO_ASYNC];
  160. return async_routine (io_object, notify_port,
  161. async_id_port, async_id_portPoly);
  162. }
  163. /* io mod owner */
  164. typedef kern_return_t (*io_mod_owner_type) (io_t, pid_t);
  165. kern_return_t
  166. lisp_S_io_mod_owner (io_t io_object, pid_t owner)
  167. {
  168. if (routines[IO_MOD_OWNER] == NULL)
  169. {
  170. return EOPNOTSUPP;
  171. }
  172. io_mod_owner_type mod_owner_routine = routines[IO_MOD_OWNER];
  173. return mod_owner_routine (io_object, owner);
  174. }
  175. /* io get owner */
  176. typedef kern_return_t (*io_get_owner_type) (io_t, pid_t *);
  177. kern_return_t
  178. lisp_S_io_get_owner (io_t io_object, pid_t * owner)
  179. {
  180. if (routines[IO_GET_OWNER] == NULL)
  181. {
  182. return EOPNOTSUPP;
  183. }
  184. io_get_owner_type get_owner_routine = routines[IO_GET_OWNER];
  185. return get_owner_routine (io_object, owner);
  186. }
  187. /* io get icky async id */
  188. typedef kern_return_t (*io_get_icky_async_id) (io_t,
  189. mach_port_t *,
  190. mach_msg_type_name_t *);
  191. kern_return_t
  192. lisp_S_io_get_icky_async_id (io_t io_object,
  193. mach_port_t * icky_async_id_port,
  194. mach_msg_type_name_t * icky_async_id_portPoly)
  195. {
  196. if (routines[IO_GET_ICKY_ASYNC_ID] == NULL)
  197. {
  198. return EOPNOTSUPP;
  199. }
  200. io_get_icky_async_id get_icky_async_id_routine =
  201. routines[IO_GET_ICKY_ASYNC_ID];
  202. return get_icky_async_id_routine (io_object,
  203. icky_async_id_port,
  204. icky_async_id_portPoly);
  205. }
  206. /* io select */
  207. typedef kern_return_t (*io_select_type) (io_t, int *);
  208. kern_return_t
  209. lisp_S_io_select (io_t io_object, int *select_type)
  210. {
  211. if (routines[IO_SELECT] == NULL)
  212. {
  213. return EOPNOTSUPP;
  214. }
  215. io_select_type select_routine = routines[IO_SELECT];
  216. return select_routine (io_object, select_type);
  217. }
  218. /* io stat */
  219. typedef kern_return_t (*io_stat_type) (io_t, io_statbuf_t *);
  220. kern_return_t
  221. lisp_S_io_stat (io_t stat_object, io_statbuf_t * stat_info)
  222. {
  223. if (routines[IO_STAT] == NULL)
  224. {
  225. return EOPNOTSUPP;
  226. }
  227. io_stat_type stat_routine = routines[IO_STAT];
  228. return stat_routine (stat_object, stat_info);
  229. }
  230. /* io reauthenticate */
  231. typedef kern_return_t (*io_reauthenticate_type) (io_t, mach_port_t);
  232. kern_return_t
  233. lisp_S_io_reauthenticate (io_t auth_object, mach_port_t rendezvous2)
  234. {
  235. if (routines[IO_REAUTHENTICATE] == NULL)
  236. {
  237. return EOPNOTSUPP;
  238. }
  239. io_reauthenticate_type reauthenticate_routine = routines[IO_REAUTHENTICATE];
  240. return reauthenticate_routine (auth_object, rendezvous2);
  241. }
  242. /* io restrict auth */
  243. typedef kern_return_t (*io_restrict_auth_type) (io_t,
  244. mach_port_t *,
  245. mach_msg_type_name_t *,
  246. idarray_t,
  247. mach_msg_type_number_t,
  248. idarray_t,
  249. mach_msg_type_number_t);
  250. kern_return_t
  251. lisp_S_io_restrict_auth (io_t io_object,
  252. mach_port_t * new_object,
  253. mach_msg_type_name_t * new_objectPoly,
  254. idarray_t uids,
  255. mach_msg_type_number_t uidsCnt,
  256. idarray_t gids, mach_msg_type_number_t gidsCnt)
  257. {
  258. if (routines[IO_RESTRICT_AUTH] == NULL)
  259. {
  260. return EOPNOTSUPP;
  261. }
  262. io_restrict_auth_type restrict_auth_routine = routines[IO_RESTRICT_AUTH];
  263. return restrict_auth_routine (io_object,
  264. new_object, new_objectPoly,
  265. uids, uidsCnt, gids, gidsCnt);
  266. }
  267. /* io duplicate */
  268. typedef kern_return_t (*io_duplicate_type) (io_t,
  269. mach_port_t *,
  270. mach_msg_type_name_t *);
  271. kern_return_t
  272. lisp_S_io_duplicate (io_t io_object,
  273. mach_port_t * newport, mach_msg_type_name_t * newportPoly)
  274. {
  275. if (routines[IO_DUPLICATE] == NULL)
  276. {
  277. return EOPNOTSUPP;
  278. }
  279. io_duplicate_type duplicate_routine = routines[IO_DUPLICATE];
  280. return duplicate_routine (io_object, newport, newportPoly);
  281. }
  282. /* io server version */
  283. typedef kern_return_t (*io_server_version_type) (io_t,
  284. string_t, int *, int *,
  285. int *);
  286. kern_return_t
  287. lisp_S_io_server_version (io_t vers_object,
  288. string_t server_name,
  289. int *server_major_version,
  290. int *server_minor_version, int *server_edit_level)
  291. {
  292. if (routines[IO_SERVER_VERSION] == NULL)
  293. {
  294. return EOPNOTSUPP;
  295. }
  296. io_server_version_type server_version_routine = routines[IO_SERVER_VERSION];
  297. return server_version_routine (vers_object, server_name,
  298. server_major_version, server_minor_version,
  299. server_edit_level);
  300. }
  301. /* io map */
  302. typedef kern_return_t (*io_map_type) (io_t,
  303. mach_port_t *,
  304. mach_msg_type_name_t *,
  305. mach_port_t *, mach_msg_type_name_t *);
  306. kern_return_t
  307. lisp_S_io_map (io_t io_object,
  308. mach_port_t * memobjrd,
  309. mach_msg_type_name_t * memobjrdPoly,
  310. mach_port_t * memobjwt, mach_msg_type_name_t * memobjwtPoly)
  311. {
  312. if (routines[IO_MAP] == NULL)
  313. {
  314. return EOPNOTSUPP;
  315. }
  316. io_map_type map_routine = routines[IO_MAP];
  317. return map_routine (io_object, memobjrd,
  318. memobjrdPoly, memobjwt, memobjwtPoly);
  319. }
  320. /* io map cntl */
  321. typedef kern_return_t (*io_map_cntl_type) (io_t,
  322. mach_port_t *,
  323. mach_msg_type_name_t *);
  324. kern_return_t
  325. lisp_S_io_map_cntl (io_t io_object,
  326. mach_port_t * memobj, mach_msg_type_name_t * memobjPoly)
  327. {
  328. if (routines[IO_MAP_CNTL] == NULL)
  329. {
  330. return EOPNOTSUPP;
  331. }
  332. io_map_cntl_type map_cntl_routine = routines[IO_MAP_CNTL];
  333. return map_cntl_routine (io_object, memobj, memobjPoly);
  334. }
  335. /* io get conch */
  336. typedef kern_return_t (*io_get_conch_type) (io_t);
  337. kern_return_t
  338. lisp_S_io_get_conch (io_t io_object)
  339. {
  340. if (routines[IO_GET_CONCH] == NULL)
  341. {
  342. return EOPNOTSUPP;
  343. }
  344. io_get_conch_type get_conch_routine = routines[IO_GET_CONCH];
  345. return get_conch_routine (io_object);
  346. }
  347. /* io release conch */
  348. typedef kern_return_t (*io_release_conch_type) (io_t);
  349. kern_return_t
  350. lisp_S_io_release_conch (io_t io_object)
  351. {
  352. if (routines[IO_RELEASE_CONCH] == NULL)
  353. {
  354. return EOPNOTSUPP;
  355. }
  356. io_release_conch_type release_conch_routine = routines[IO_RELEASE_CONCH];
  357. return release_conch_routine (io_object);
  358. }
  359. /* io eofnotify */
  360. typedef kern_return_t (*io_eofnotify_type) (io_t);
  361. kern_return_t
  362. lisp_S_io_eofnotify (io_t io_object)
  363. {
  364. if (routines[IO_EOFNOTIFY] == NULL)
  365. {
  366. return EOPNOTSUPP;
  367. }
  368. io_eofnotify_type eofnotify_routine = routines[IO_EOFNOTIFY];
  369. return eofnotify_routine (io_object);
  370. }
  371. /* io prenotify */
  372. typedef kern_return_t (*io_prenotify_type) (io_t, vm_offset_t, vm_offset_t);
  373. kern_return_t
  374. lisp_S_io_prenotify (io_t io_object,
  375. vm_offset_t write_start, vm_offset_t write_end)
  376. {
  377. if (routines[IO_PRENOTIFY] == NULL)
  378. {
  379. return EOPNOTSUPP;
  380. }
  381. io_prenotify_type prenotify_routine = routines[IO_PRENOTIFY];
  382. return prenotify_routine (io_object, write_start, write_end);
  383. }
  384. /* io postnotify */
  385. typedef kern_return_t (*io_postnotify_type) (io_t, vm_offset_t, vm_offset_t);
  386. kern_return_t
  387. lisp_S_io_postnotify (io_t io_object,
  388. vm_offset_t write_start, vm_offset_t write_end)
  389. {
  390. if (routines[IO_POSTNOTIFY] == NULL)
  391. {
  392. return EOPNOTSUPP;
  393. }
  394. io_postnotify_type postnotify_routine = routines[IO_POSTNOTIFY];
  395. return postnotify_routine (io_object, write_start, write_end);
  396. }
  397. /* io readnotify */
  398. typedef kern_return_t (*io_readnotify_type) (io_t);
  399. kern_return_t
  400. lisp_S_io_readnotify (io_t io_object)
  401. {
  402. if (routines[IO_READNOTIFY] == NULL)
  403. {
  404. return EOPNOTSUPP;
  405. }
  406. io_readnotify_type readnotify_routine = routines[IO_READNOTIFY];
  407. return readnotify_routine (io_object);
  408. }
  409. /* io readsleep */
  410. typedef kern_return_t (*io_readsleep_type) (io_t);
  411. kern_return_t
  412. lisp_S_io_readsleep (io_t io_object)
  413. {
  414. if (routines[IO_READSLEEP] == NULL)
  415. {
  416. return EOPNOTSUPP;
  417. }
  418. io_readsleep_type readsleep_routine = routines[IO_READSLEEP];
  419. return readsleep_routine (io_object);
  420. }
  421. /* io sigio */
  422. typedef kern_return_t (*io_sigio_type) (io_t);
  423. kern_return_t
  424. lisp_S_io_sigio (io_t io_object)
  425. {
  426. if (routines[IO_SIGIO] == NULL)
  427. {
  428. return EOPNOTSUPP;
  429. }
  430. io_sigio_type sigio_routine = routines[IO_SIGIO];
  431. return sigio_routine (io_object);
  432. }
  433. /* io pathconf */
  434. typedef kern_return_t (*io_pathconf_type) (io_t, int, int *);
  435. kern_return_t
  436. lisp_S_io_pathconf (io_t io_object, int name, int *value)
  437. {
  438. if (routines[IO_PATHCONF] == NULL)
  439. {
  440. return EOPNOTSUPP;
  441. }
  442. io_pathconf_type pathconf_routine = routines[IO_PATHCONF];
  443. return pathconf_routine (io_object, name, value);
  444. }
  445. /* io identity */
  446. typedef kern_return_t (*io_identity_type) (io_t,
  447. mach_port_t *,
  448. mach_msg_type_name_t *,
  449. mach_port_t *,
  450. mach_msg_type_name_t *, ino64_t *);
  451. kern_return_t
  452. lisp_S_io_identity (io_t io_object,
  453. mach_port_t * idport,
  454. mach_msg_type_name_t * idportPoly,
  455. mach_port_t * fsidport,
  456. mach_msg_type_name_t * fsidportPoly, ino64_t * fileno)
  457. {
  458. if (routines[IO_IDENTITY] == NULL)
  459. {
  460. return EOPNOTSUPP;
  461. }
  462. io_identity_type identity_routine = routines[IO_IDENTITY];
  463. return identity_routine (io_object, idport,
  464. idportPoly, fsidport, fsidportPoly, fileno);
  465. }
  466. /* io revoke */
  467. typedef kern_return_t (*io_revoke_type) (io_t);
  468. kern_return_t
  469. lisp_S_io_revoke (io_t io_object)
  470. {
  471. if (routines[IO_REVOKE] == NULL)
  472. {
  473. return EOPNOTSUPP;
  474. }
  475. io_revoke_type revoke_routine = routines[IO_REVOKE];
  476. return revoke_routine (io_object);
  477. }
  478. static const char *
  479. routine_to_str (const IoRoutine rot)
  480. {
  481. #define RET(val) case val: return #val ;
  482. switch (rot)
  483. {
  484. RET (IO_WRITE)
  485. RET (IO_READ)
  486. RET (IO_SEEK)
  487. RET (IO_READABLE)
  488. RET (IO_SET_SOME_OPENMODES)
  489. RET (IO_SET_ALL_OPENMODES)
  490. RET (IO_GET_OPENMODES)
  491. RET (IO_CLEAR_SOME_OPENMODES)
  492. RET (IO_ASYNC)
  493. RET (IO_MOD_OWNER)
  494. RET (IO_GET_OWNER)
  495. RET (IO_GET_ICKY_ASYNC_ID)
  496. RET (IO_SELECT)
  497. RET (IO_STAT)
  498. RET (IO_REAUTHENTICATE)
  499. RET (IO_RESTRICT_AUTH)
  500. RET (IO_DUPLICATE)
  501. RET (IO_SERVER_VERSION)
  502. RET (IO_MAP)
  503. RET (IO_MAP_CNTL)
  504. RET (IO_GET_CONCH)
  505. RET (IO_RELEASE_CONCH)
  506. RET (IO_EOFNOTIFY)
  507. RET (IO_PRENOTIFY)
  508. RET (IO_POSTNOTIFY)
  509. RET (IO_READNOTIFY)
  510. RET (IO_READSLEEP)
  511. RET (IO_SIGIO)
  512. RET (IO_PATHCONF)
  513. RET (IO_IDENTITY)
  514. RET (IO_REVOKE)
  515. case _NUMBER_OF_ROUTINES:
  516. default:
  517. return "";
  518. }
  519. #undef RET
  520. }
  521. #include "common.c"
  522. COMMON_FUNCTIONS (io);