Val _lib7_P_SysDB_getpwnam (Task* task, Val arg) { //====================== // // _lib7_P_SysDB_getpwnam : String -> (String, word, word, String, String) // // Get password file entry by name. // // This fn gets bound as getpwnam' in: // // src/lib/std/src/posix-1003.1b/posix-etc.pkg ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_P_SysDB_getpwnam"); struct passwd* info; // We cannot reference anything on the Mythryl // heap between RELEASE_MYTHRYL_HEAP and RECOVER_MYTHRYL_HEAP // because garbage collection might be moving // it around, so copy heap_path into C storage: // Mythryl_Heap_Value_Buffer name_buf; // { char* heap_name = HEAP_STRING_AS_C_STRING( arg ); char* c_name = buffer_mythryl_heap_value( &name_buf, (void*) heap_name, strlen( heap_name ) +1 ); // '+1' for terminal NUL on string. RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_P_SysDB_getpwnam", NULL ); // info = getpwnam( c_name ); // RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_P_SysDB_getpwnam" ); unbuffer_mythryl_heap_value( &name_buf ); } if (info == NULL) return RAISE_SYSERR__MAY_HEAPCLEAN(task, -1, NULL); Val pw_name = make_ascii_string_from_c_string__may_heapclean( task, info->pw_name, NULL ); Roots roots1 = { &pw_name, NULL }; Val pw_uid = make_one_word_unt( task, (Vunt) (info->pw_uid) ); Roots roots2 = { &pw_uid, &roots1 }; Val pw_gid = make_one_word_unt( task, (Vunt) (info->pw_gid) ); Roots roots3 = { &pw_gid, &roots2 }; Val pw_dir = make_ascii_string_from_c_string__may_heapclean( task, info->pw_dir, &roots3 ); Roots roots4 = { &pw_dir, &roots3 }; Val pw_shell = make_ascii_string_from_c_string__may_heapclean( task, info->pw_shell, &roots4 ); return make_five_slot_record(task, pw_name, pw_uid, pw_gid, pw_dir, pw_shell ); }
Val _lib7_P_FileSys_umask (Task* task, Val arg) { //===================== // // Mythryl type : Unt -> Unt // // Set and get file creation mask // Assumes umask never fails. // // This fn gets bound as umask' in: // // src/lib/std/src/psx/posix-file.pkg // src/lib/std/src/psx/posix-file-system-64.pkg ENTER_MYTHRYL_CALLABLE_C_FN(__func__); RELEASE_MYTHRYL_HEAP( task->hostthread, __func__, NULL ); // mode_t omask = umask(WORD_LIB7toC(arg)); // RECOVER_MYTHRYL_HEAP( task->hostthread, __func__ ); Val result = make_one_word_unt(task, (Vunt) omask ); EXIT_MYTHRYL_CALLABLE_C_FN(__func__); return result; }
Val _util_NetDB_mknetent (Task *task, struct netent* nentry) { //==================== // // Allocate a Mythryl value of type // Null_Or( (String, List(String), Addr_Family, Sysword) ) // to represent a struct netent value. if (nentry == NULL) return OPTION_NULL; // Build the return result: // If our agegroup0 buffer is more than half full, // empty it by doing a heapcleaning. This is very // conservative -- which is the way I like it. :-) // if (agegroup0_freespace_in_bytes( task ) < agegroup0_usedspace_in_bytes( task ) ){ call_heapcleaner( task, 0 ); } Val name = make_ascii_string_from_c_string__may_heapclean( task, nentry->n_name, NULL ); Roots roots1 = { &name, NULL }; Val aliases = make_ascii_strings_from_vector_of_c_strings__may_heapclean( task, nentry->n_aliases, &roots1 ); Roots roots2 = { &aliases, &roots1 }; Val af = make_system_constant__may_heapclean( task, &_Sock_AddrFamily, nentry->n_addrtype, &roots2 ); // Roots roots3 = { &af, &roots2 }; Val net = make_one_word_unt( task, (Vunt) (nentry->n_net) ); // Roots roots4 = { &net, &roots3 }; Val result = make_four_slot_record( task, name, aliases, af, net ); return OPTION_THE( task, result ); }
/* _lib7_win32_PS_create_process : String -> one_word_unt * * Note: This function returns the handle to the created process * This handle will need to be freed before the system releases * the memory associated to the process. * We will take care of this in the wait_for_single_chunk * call. This is for the time being only used by threadkit. * It could also cause problems later on. */ Val _lib7_win32_PS_create_process(Task *task, Val arg) { char *str = HEAP_STRING_AS_C_STRING(arg); PROCESS_INFORMATION pi; STARTUPINFO si; BOOL fSuccess; ZeroMemory (&si,sizeof(si)); si.cb = sizeof(si); fSuccess = CreateProcess (NULL,str,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); if (fSuccess) { HANDLE hProcess = pi.hProcess; CloseHandle (pi.hThread); return make_one_word_unt(task, (Vunt) hProcess ); } return make_one_word_unt(task, (Vunt) 0 ); }
Val _lib7_P_TTY_tcgetattr (Task* task, Val arg) { //===================== // // Mythryl type: Int -> (Unt, Unt, Unt, Unt, String, Unt, Unt) // // Get parameters associated with tty. // // NOTE: the calls to cfget[io] speed by making the code more OS-dependent // and using the package of struct termios. // // This fn gets bound as tcgetattr in: // // src/lib/std/src/psx/posix-tty.pkg ENTER_MYTHRYL_CALLABLE_C_FN(__func__); int fd = TAGGED_INT_TO_C_INT( arg ); struct termios data; RELEASE_MYTHRYL_HEAP( task->hostthread, __func__, NULL); // int status = tcgetattr( fd, &data ); // RECOVER_MYTHRYL_HEAP( task->hostthread, __func__ ); if (status < 0) return RAISE_SYSERR__MAY_HEAPCLEAN(task, status, NULL); Val iflag = make_one_word_unt(task, data.c_iflag ); Roots roots1 = { &iflag, NULL }; Val oflag = make_one_word_unt(task, data.c_oflag ); Roots roots2 = { &oflag, &roots1 }; Val cflag = make_one_word_unt(task, data.c_cflag ); Roots roots3 = { &cflag, &roots2 }; Val lflag = make_one_word_unt(task, data.c_lflag ); Roots roots4 = { &lflag, &roots3 }; Val ispeed = make_one_word_unt(task, cfgetispeed (&data) ); Roots roots5 = { &ispeed, &roots4 }; Val ospeed = make_one_word_unt(task, cfgetospeed (&data) ); Roots roots6 = { &ospeed, &roots5 }; Val cc = allocate_nonempty_ascii_string__may_heapclean (task, NCCS, &roots6 ); memcpy( GET_VECTOR_DATACHUNK_AS( void*, cc ), data.c_cc, NCCS ); // Construct the result vector: // set_slot_in_nascent_heapchunk (task, 0, MAKE_TAGWORD(PAIRS_AND_RECORDS_BTAG, 7)); set_slot_in_nascent_heapchunk (task, 1, iflag); set_slot_in_nascent_heapchunk (task, 2, oflag); set_slot_in_nascent_heapchunk (task, 3, cflag); set_slot_in_nascent_heapchunk (task, 4, lflag); set_slot_in_nascent_heapchunk (task, 5, cc); set_slot_in_nascent_heapchunk (task, 6, ispeed); set_slot_in_nascent_heapchunk (task, 7, ospeed); Val result = commit_nascent_heapchunk (task, 7); EXIT_MYTHRYL_CALLABLE_C_FN(__func__); return result; }
Val _lib7_U_Dynload_dlopen (Task* task, Val arg) { // (String, Bool, Bool) -> one_word_unt::Unt //====================== // // Open a dynamically loaded library. // ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_U_Dynload_dlopen"); Val ml_libname = GET_TUPLE_SLOT_AS_VAL (arg, 0); int lazy = GET_TUPLE_SLOT_AS_VAL (arg, 1) == HEAP_TRUE; int global = GET_TUPLE_SLOT_AS_VAL (arg, 2) == HEAP_TRUE; char *libname = NULL; void *handle; Mythryl_Heap_Value_Buffer libname_buf; if (ml_libname != OPTION_NULL) { // libname = HEAP_STRING_AS_C_STRING (OPTION_GET (ml_libname)); // // Copy libname out of Mythryl heap to // make it safe to reference between // RELEASE_MYTHRYL_HEAP and // RECOVER_MYTHRYL_HEAP: // libname = (char*) buffer_mythryl_heap_value( &libname_buf, (void*)libname, strlen(libname)+1 ); // '+1' for terminal NUL on string. } #ifdef OPSYS_WIN32 handle = (void *) LoadLibrary (libname); if (handle == NULL && libname != NULL) dlerror_set ("Library `%s' not found", libname); #else int flag = (lazy ? RTLD_LAZY : RTLD_NOW); if (global) flag |= RTLD_GLOBAL; RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_U_Dynload_dlopen", NULL ); // handle = dlopen (libname, flag); // RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_U_Dynload_dlopen" ); #endif if (libname) unbuffer_mythryl_heap_value( &libname_buf ); return make_one_word_unt(task, (Vunt) handle ); }
Val _lib7_win32_PS_wait_for_single_chunk(Task *task, Val arg) { HANDLE hProcess = (HANDLE) WORD_LIB7toC (arg); DWORD exit_code; int res; Val p; res = WaitForSingleChunkect (hProcess,0); if (res==WAIT_TIMEOUT || res==WAIT_FAILED) { /* information is not ready, or error */ return OPTION_NULL; } else { /* WAIT_CHUNKECT_0 ... done, finished */ /* get info and return THE(exit_status) */ GetExitCodeProcess (hProcess,&exit_code); CloseHandle (hProcess); /* decrease ref count */ p = make_one_word_unt(task, (Vunt) exit_code ); return OPTION_THE( task, p ); } }
Val _lib7_P_ProcEnv_getegid (Task* task, Val arg) { //======================= // // _lib7_P_ProcEnv_getegid: Void -> word // // Return effective group id // // This fn gets bound as get_effective_group_id in: // // src/lib/std/src/posix-1003.1b/posix-id.pkg ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_P_ProcEnv_getegid"); RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_P_ProcEnv_getegid", NULL ); // int egid = getegid(); // RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_P_ProcEnv_getegid" ); return make_one_word_unt(task, (Vunt)egid ); }
Val _lib7_P_ProcEnv_getuid (Task* task, Val arg) { //====================== // // Mythryl type: Void -> Unt // // Return user id. // // This fn gets bound as get_user_id in: // // src/lib/std/src/posix-1003.1b/posix-id.pkg ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_P_ProcEnv_getuid"); RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_P_ProcEnv_getuid", NULL ); // int uid = getuid (); // RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_P_ProcEnv_getuid" ); return make_one_word_unt(task, (Vunt) uid ); }
Val _lib7_P_ProcEnv_getuid (Task* task, Val arg) { //====================== // // Mythryl type: Void -> Unt // // Return user id. // // This fn gets bound as get_user_id in: // // src/lib/std/src/psx/posix-id.pkg ENTER_MYTHRYL_CALLABLE_C_FN(__func__); RELEASE_MYTHRYL_HEAP( task->hostthread, __func__, NULL ); // int uid = getuid (); // RECOVER_MYTHRYL_HEAP( task->hostthread, __func__ ); Val result = make_one_word_unt(task, (Vunt) uid ); EXIT_MYTHRYL_CALLABLE_C_FN(__func__); return result; }
/* _lib7_win32_PS_bin_sh: String -> one_word_unt * command * */ Val _lib7_win32_PS_bin_sh(Task *task, Val arg) { int ret = system(HEAP_STRING_AS_C_STRING(arg)); // return make_one_word_unt(task, (Vunt) ret ); }