1 /** 2 * xrdp: A Remote Desktop Protocol server. 3 * 4 * Copyright (C) Jay Sorg 2004-2014 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * generic operating system calls 19 */ 20 21 #if !defined(OS_CALLS_H) 22 #define OS_CALLS_H 23 24 #include "arch.h" 25 26 struct exit_status 27 { 28 /* set to -1 when the process exited via a signal */ 29 uint8_t exit_code; 30 31 /* set to 0 when the process exited normally */ 32 uint8_t signal_no; 33 }; 34 35 #define g_tcp_can_recv g_sck_can_recv 36 #define g_tcp_can_send g_sck_can_send 37 #define g_tcp_recv g_sck_recv 38 #define g_tcp_send g_sck_send 39 #define g_tcp_close g_sck_close 40 #define g_tcp_last_error_would_block g_sck_last_error_would_block 41 #define g_tcp_set_non_blocking g_sck_set_non_blocking 42 #define g_tcp_local_socket g_sck_local_socket 43 #define g_tcp_local_connect g_sck_local_connect 44 #define g_tcp_listen g_sck_listen 45 #define g_tcp_local_bind g_sck_local_bind 46 #define g_tcp_select g_sck_select 47 #define g_close_wait_obj g_delete_wait_obj 48 49 int g_rm_temp_dir(void); 50 int g_mk_socket_path(const char *app_name); 51 void g_init(const char *app_name); 52 void g_deinit(void); 53 void *g_malloc(int size, int zero); 54 void g_free(void *ptr); 55 void g_printf(const char *format, ...) printflike(1, 2); 56 void g_sprintf(char *dest, const char *format, ...) \ 57 printflike(2, 3); 58 int g_snprintf(char *dest, int len, const char *format, ...) \ 59 printflike(3, 4); 60 void g_writeln(const char *format, ...) printflike(1, 2); 61 void g_write(const char *format, ...) printflike(1, 2); 62 void g_hexdump(const char *p, int len); 63 void g_memset(void *ptr, int val, int size); 64 void g_memcpy(void *d_ptr, const void *s_ptr, int size); 65 int g_getchar(void); 66 int g_tcp_set_no_delay(int sck); 67 int g_tcp_set_keepalive(int sck); 68 int g_tcp_socket(void); 69 int g_sck_set_send_buffer_bytes(int sck, int bytes); 70 int g_sck_get_send_buffer_bytes(int sck, int *bytes); 71 int g_sck_set_recv_buffer_bytes(int sck, int bytes); 72 int g_sck_get_recv_buffer_bytes(int sck, int *bytes); 73 int g_sck_local_socket(void); 74 int g_sck_vsock_socket(void); 75 int g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid); 76 void g_sck_close(int sck); 77 int g_tcp_connect(int sck, const char *address, const char *port); 78 int g_sck_local_connect(int sck, const char *port); 79 int g_sck_set_non_blocking(int sck); 80 int g_tcp_bind(int sck, const char *port); 81 int g_sck_local_bind(int sck, const char *port); 82 int g_sck_vsock_bind(int sck, const char *port); 83 int g_sck_vsock_bind_address(int sck, const char *port, const char *address); 84 int g_tcp_bind_address(int sck, const char *port, const char *address); 85 int g_sck_listen(int sck); 86 int g_tcp_accept(int sck); 87 int g_sck_accept(int sck, char *addr, int addr_bytes, 88 char *port, int port_bytes); 89 int g_sck_recv(int sck, void *ptr, int len, int flags); 90 int g_sck_send(int sck, const void *ptr, int len, int flags); 91 int g_sck_last_error_would_block(int sck); 92 int g_sck_socket_ok(int sck); 93 int g_sck_can_send(int sck, int millis); 94 int g_sck_can_recv(int sck, int millis); 95 int g_sck_select(int sck1, int sck2); 96 void g_write_ip_address(int rcv_sck, char *ip_address, int bytes); 97 void g_sleep(int msecs); 98 tintptr g_create_wait_obj(const char *name); 99 tintptr g_create_wait_obj_from_socket(tintptr socket, int write); 100 void g_delete_wait_obj_from_socket(tintptr wait_obj); 101 int g_set_wait_obj(tintptr obj); 102 int g_reset_wait_obj(tintptr obj); 103 int g_is_wait_obj_set(tintptr obj); 104 int g_delete_wait_obj(tintptr obj); 105 int g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs, 106 int wcount, int mstimeout); 107 void g_random(char *data, int len); 108 int g_abs(int i); 109 int g_memcmp(const void *s1, const void *s2, int len); 110 int g_file_open(const char *file_name); 111 int g_file_open_ex(const char *file_name, int aread, int awrite, 112 int acreate, int atrunc); 113 int g_file_close(int fd); 114 int g_file_read(int fd, char *ptr, int len); 115 int g_file_write(int fd, const char *ptr, int len); 116 int g_file_seek(int fd, int offset); 117 int g_file_lock(int fd, int start, int len); 118 int g_chmod_hex(const char *filename, int flags); 119 int g_chown(const char *name, int uid, int gid); 120 int g_mkdir(const char *dirname); 121 char *g_get_current_dir(char *dirname, int maxlen); 122 int g_set_current_dir(const char *dirname); 123 int g_file_exist(const char *filename); 124 int g_file_readable(const char *filename); 125 int g_directory_exist(const char *dirname); 126 int g_create_dir(const char *dirname); 127 int g_create_path(const char *path); 128 int g_remove_dir(const char *dirname); 129 int g_file_delete(const char *filename); 130 int g_file_get_size(const char *filename); 131 long g_load_library(char *in); 132 int g_free_library(long lib); 133 void *g_get_proc_address(long lib, const char *name); 134 int g_system(char *aexec); 135 char *g_get_strerror(void); 136 int g_get_errno(void); 137 int g_execvp(const char *p1, char *args[]); 138 int g_execlp3(const char *a1, const char *a2, const char *a3); 139 void g_signal_child_stop(void (*func)(int)); 140 void g_signal_segfault(void (*func)(int)); 141 void g_signal_hang_up(void (*func)(int)); 142 void g_signal_user_interrupt(void (*func)(int)); 143 void g_signal_terminate(void (*func)(int)); 144 void g_signal_pipe(void (*func)(int)); 145 void g_signal_usr1(void (*func)(int)); 146 int g_fork(void); 147 int g_setgid(int pid); 148 int g_initgroups(const char *user, int gid); 149 int g_getuid(void); 150 int g_getgid(void); 151 int g_setuid(int pid); 152 int g_setsid(void); 153 int g_getlogin(char *name, unsigned int len); 154 int g_setlogin(const char *name); 155 int g_waitchild(void); 156 int g_waitpid(int pid); 157 struct exit_status g_waitpid_status(int pid); 158 void g_clearenv(void); 159 int g_setenv(const char *name, const char *value, int rewrite); 160 char *g_getenv(const char *name); 161 int g_exit(int exit_code); 162 int g_getpid(void); 163 int g_sigterm(int pid); 164 int g_getuser_info(const char *username, int *gid, int *uid, char **shell, 165 char **dir, char **gecos); 166 int g_getgroup_info(const char *groupname, int *gid); 167 int g_check_user_in_group(const char *username, int gid, int *ok); 168 int g_time1(void); 169 int g_time2(void); 170 int g_time3(void); 171 int g_save_to_bmp(const char *filename, char *data, int stride_bytes, 172 int width, int height, int depth, int bits_per_pixel); 173 void *g_shmat(int shmid); 174 int g_shmdt(const void *shmaddr); 175 int g_gethostname(char *name, int len); 176 int g_mirror_memcpy(void *dst, const void *src, int len); 177 int g_tcp4_socket(void); 178 int g_tcp4_bind_address(int sck, const char *port, const char *address); 179 int g_tcp6_socket(void); 180 int g_tcp6_bind_address(int sck, const char *port, const char *address); 181 182 /* glib-style wrappers */ 183 #define g_new(struct_type, n_structs) \ 184 (struct_type *) malloc(sizeof(struct_type) * (n_structs)) 185 #define g_new0(struct_type, n_structs) \ 186 (struct_type *) calloc((n_structs), sizeof(struct_type)) 187 188 #endif 189