|
| 1 | +// |
| 2 | +// LinuxInterop.h |
| 3 | +// iSH |
| 4 | +// |
| 5 | +// Created by Theodore Dubois on 7/3/21. |
| 6 | +// |
| 7 | + |
| 8 | +#ifndef LinuxInterop_h |
| 9 | +#define LinuxInterop_h |
| 10 | + |
| 11 | +#ifndef __KERNEL__ |
| 12 | +#include <sys/types.h> |
| 13 | +#else |
| 14 | +#include <linux/types.h> |
| 15 | +#include <linux/fs.h> |
| 16 | +#endif |
| 17 | + |
| 18 | +void async_do_in_irq(void (^block)(void)); |
| 19 | +void async_do_in_workqueue(void (^block)(void)); |
| 20 | +void async_do_in_ios(void (^block)(void)); |
| 21 | +void sync_do_in_workqueue(void (^block)(void (^done)(void))); |
| 22 | + |
| 23 | +// call into ios from kernel: |
| 24 | + |
| 25 | +void actuate_kernel(const char *cmdline); |
| 26 | + |
| 27 | +void ReportPanic(const char *message); |
| 28 | +void ConsoleLog(const char *data, unsigned len); |
| 29 | +const char *DefaultRootPath(void); |
| 30 | + |
| 31 | +typedef const void *nsobj_t; |
| 32 | +nsobj_t objc_get(nsobj_t object); |
| 33 | +void objc_put(nsobj_t object); |
| 34 | + |
| 35 | +struct linux_tty { |
| 36 | + struct linux_tty_callbacks *ops; |
| 37 | +}; |
| 38 | +struct linux_tty_callbacks { |
| 39 | + void (*can_output)(struct linux_tty *tty); |
| 40 | + void (*send_input)(struct linux_tty *tty, const char *data, size_t length); |
| 41 | + void (*resize)(struct linux_tty *tty, int cols, int rows); |
| 42 | + void (*hangup)(struct linux_tty *tty); |
| 43 | +}; |
| 44 | + |
| 45 | +#ifdef __KERNEL__ |
| 46 | +struct file *ios_pty_open(nsobj_t *terminal_out); |
| 47 | +#endif |
| 48 | + |
| 49 | +nsobj_t Terminal_terminalWithType_number(int type, int number); |
| 50 | +void Terminal_setLinuxTTY(nsobj_t _self, struct linux_tty *tty); |
| 51 | +int Terminal_sendOutput_length(nsobj_t _self, const char *data, int size); |
| 52 | +int Terminal_roomForOutput(nsobj_t _self); |
| 53 | + |
| 54 | +nsobj_t UIPasteboard_get(void); |
| 55 | +long UIPasteboard_changeCount(void); |
| 56 | +void UIPasteboard_set(const char *data, size_t len); |
| 57 | +size_t NSData_length(nsobj_t data); |
| 58 | +const void *NSData_bytes(nsobj_t data); |
| 59 | + |
| 60 | +// call into kernel from ios: |
| 61 | + |
| 62 | +typedef void (^StartSessionDoneBlock)(int retval, int pid, nsobj_t terminal); |
| 63 | +void linux_start_session(const char *exe, const char *const *argv, const char *const *envp, StartSessionDoneBlock done); |
| 64 | + |
| 65 | +void linux_sethostname(const char *hostname); |
| 66 | + |
| 67 | +ssize_t linux_read_file(const char *path, char *buf, size_t size); |
| 68 | +ssize_t linux_write_file(const char *path, const char *buf, size_t size); |
| 69 | +int linux_remove_directory(const char *path); |
| 70 | + |
| 71 | +#endif /* LinuxInterop_h */ |
0 commit comments