ikptr ikrt_accept(ikptr s, ikptr bv /*, ikpcb* pcb */){ socklen_t addrlen = unfix(ref(bv, off_bytevector_length)); int sock = accept(unfix(s), (struct sockaddr*) (bv+off_bytevector_data), &addrlen); if(sock < 0){ return ik_errno_to_code(); } ref(bv, off_bytevector_length) = fix(addrlen); return fix(sock); }
ikptr ikrt_shutdown(ikptr s /*, ikpcb* pcb*/){ #ifdef __CYGWIN__ int err = close(unfix(s)); #else int err = shutdown(unfix(s), SHUT_RDWR); #endif if(err < 0){ return ik_errno_to_code(); } return 0; }
ikptr ikrt_gmt_offset(ikptr t){ time_t clock = unfix(ref(t, off_record_data + 0*wordsize)) * 1000000 + unfix(ref(t, off_record_data + 1*wordsize)); struct tm* m = gmtime(&clock); time_t gmtclock = mktime(m); return fix(clock - gmtclock); /* struct tm* m = localtime(&clock); ikptr r = fix(m->tm_gmtoff); return r; */ }
ikptr ik_sigprocmask(ikptr how, ikptr sigcodes, ikptr get_old, ikpcb* pcb){ int h = 0; sigset_t s, o; sigset_t* ps, * po; if (sigcodes != false_object){ int u = unfix(how); if (1==u) h = SIG_BLOCK; else if (2==u) h = SIG_SETMASK; else if (3==u) h = SIG_UNBLOCK; ps = &s; sigemptyset(ps); ik_sigset(ps, sigcodes); } else ps = NULL; if (get_old != false_object){ po = &o; sigemptyset(po); } else po = NULL; if (sigprocmask(h, ps, po)) return ik_errno_to_code(); else if (po) return ik_sigmembers(po, pcb); else return true_object; }
ikptr ikrt_open_output_fd(ikptr fn, ikptr ikopts /*, ikpcb* pcb */){ int opts = unfix(ikopts); int mode = 0; switch (opts){ /* mode 0: error if exists, create if does not exist */ case 0: mode = O_WRONLY | O_CREAT | O_EXCL; break; /* mode 1: truncate if exists, error if not exists */ case 1: mode = O_WRONLY | O_TRUNC; break; /* mode 2: truncate if exists, create if not exist */ case 2: mode = O_WRONLY | O_TRUNC | O_CREAT ; break; /* mode 3: truncate if exists, error if not exists */ case 3: mode = O_WRONLY | O_TRUNC ; break; case 4: mode = O_WRONLY | O_CREAT | O_EXCL ; break; case 5: mode = O_WRONLY | O_CREAT ; break; case 6: mode = O_WRONLY | O_CREAT ; break; case 7: mode = O_WRONLY ; break; } int fh = open((char*)(long)(fn+off_bytevector_data), mode, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(fh >= 0){ return fix(fh); } else { return ik_errno_to_code(); } }
ikptr ikrt_listen(ikptr port /*, ikpcb* pcb */){ int sock = socket(AF_INET, SOCK_STREAM, 0); if(sock < 0){ return ik_errno_to_code(); } struct sockaddr_in servaddr; memset(&servaddr, 0, sizeof(struct sockaddr_in)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(unfix(port)); int err; int reuse = 1; err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)); if(err < 0){ return ik_errno_to_code(); } err = bind(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)); if(err < 0){ return ik_errno_to_code(); } err = listen(sock, 1024); if(err < 0){ return ik_errno_to_code(); } return fix(sock); }
static ffi_type* scheme_to_ffi_type_cast(ikptr nptr){ if (tagof(nptr) == vector_tag) { return scheme_to_ffi_record_type_cast(nptr); } else if (is_fixnum(nptr)) { long n = unfix(nptr); switch (n & 0xF) { case 1: return &ffi_type_void; case 2: return &ffi_type_uint8; case 3: return &ffi_type_sint8; case 4: return &ffi_type_uint16; case 5: return &ffi_type_sint16; case 6: return &ffi_type_uint32; case 7: return &ffi_type_sint32; case 8: return (sizeof(long)==4)?&ffi_type_uint32:&ffi_type_uint64; case 9: return (sizeof(long)==4)?&ffi_type_sint32:&ffi_type_sint64; case 10: return &ffi_type_uint64; case 11: return &ffi_type_sint64; case 12: return &ffi_type_float; case 13: return &ffi_type_double; case 14: return &ffi_type_pointer; default: fprintf(stderr, "INVALID ARG %ld", n); exit(-1); } } else { fprintf(stderr, "INVALID ARG %ld", nptr); exit(-1); } }
ikptr ikrt_kill(ikptr pid, ikptr sigcode /*, ikpcb* pcb */){ int r = kill((pid_t)unfix(pid), ik_signal_code_to_num(sigcode)); if(r == 0){ return fix(0); } return ik_errno_to_code(); }
/** Remove all ties */ void ParamFunction::clearTies() { for (auto &tie : m_ties) { size_t i = getParameterIndex(*tie); unfix(i); delete tie; } m_ties.clear(); }
ikptr ikrt_chmod(ikptr path, ikptr mode /*, ikpcb* pcb */){ int r = chmod((char*)(path+off_bytevector_data), (mode_t)unfix(mode)); if(r == 0){ return true_object; } return ik_errno_to_code(); }
void fixable_page_h::fix_nonbufferpool_page(generic_page* s) { w_assert1(s != NULL); unfix(); _pp = s; _bufferpool_managed = false; _mode = LATCH_EX; }
ikptr ikrt_write_fd(ikptr fd, ikptr bv, ikptr off, ikptr cnt /*, ikpcb* pcb */){ #if 0 if (0) { fprintf(stderr, "WRITE %d, %p %d %d %d\n", unfix(fd), bv, unfix(ref(bv, off_bytevector_length)), unfix(off), unfix(cnt)); int i; for(i=0; i<100; i++){ fprintf(stderr, "bv[%d]=0x%02x ", i, ((char*)(bv+off_bytevector_data))[i]); } fprintf(stderr, "\n"); } #endif ssize_t bytes = write(unfix(fd), (char*)(long)(bv+off_bytevector_data+unfix(off)), unfix(cnt)); if(bytes >= 0){ return fix(bytes); } else { return ik_errno_to_code(); } }
ikptr ikrt_make_fd_nonblocking(ikptr fdptr /*, ikpcb* pcb */){ int fd = unfix(fdptr); int err = fcntl(fd, F_SETFL, O_NONBLOCK); if(err == -1){ return ik_errno_to_code(); } return 0; }
ikptr ikrt_read_fd(ikptr fd, ikptr bv, ikptr off, ikptr cnt /*, ikpcb* pcb */){ #if 0 fprintf(stderr, "READ: %d\n", unfix(fd)); #endif ssize_t bytes = read(unfix(fd), (char*)(long)(bv+off_bytevector_data+unfix(off)), unfix(cnt)); #if 0 fprintf(stderr, "BYTES: %d\n", bytes); #endif if(bytes >= 0){ return fix(bytes); } else { return ik_errno_to_code(); } }
ikptr ikrt_close_fd(ikptr fd /*, ikpcb* pcb */){ int err = close(unfix(fd)); if(err == -1){ return ik_errno_to_code(); } else { return false_object;; } }
ikptr ikrt_set_position(ikptr fd, ikptr pos /*, ikpcb* pcb */){ off_t offset = extract_num_longlong(pos); off_t err = lseek(unfix(fd), offset, SEEK_SET); if(err == -1){ return ik_errno_to_code(); } else { return false_object;; } }
w_rc_t fixable_page_h::refix_direct (bf_idx idx, latch_mode_t mode, bool conditional) { w_assert1(idx != 0); w_assert1(mode != LATCH_NL); unfix(); W_DO(smlevel_0::bf->refix_direct(_pp, idx, mode, conditional)); _bufferpool_managed = true; _mode = mode; return RCOK; }
/** Remove all ties */ void TiesFunction::clearTies() { for(std::vector<ParameterTie*>::iterator it = m_ties.begin();it != m_ties.end(); ++it) { size_t i = getParameterIndex(**it); unfix(i); delete *it; } m_ties.clear(); }
ikptr ikrt_select(ikptr fds, ikptr rfds, ikptr wfds, ikptr xfds /*, ikpcb* pcb */){ int rv = select(unfix(fds), (fd_set*)(rfds + off_bytevector_data), (fd_set*)(wfds + off_bytevector_data), (fd_set*)(xfds + off_bytevector_data), NULL); if(rv < 0){ return ik_errno_to_code(); } return fix(rv); }
w_rc_t fixable_page_h::fix_root (StoreID store, latch_mode_t mode, bool conditional, bool virgin) { w_assert1(mode != LATCH_NL); unfix(); W_DO(smlevel_0::bf->fix_root(_pp, store, mode, conditional, virgin)); _bufferpool_managed = true; _mode = mode; return RCOK; }
/** Removes i-th parameter's tie if it is tied or does nothing. * @param i :: The index of the tied parameter. * @return True if successfull */ bool ParamFunction::removeTie(size_t i) { if (i >= nParams()) { throw std::out_of_range("ParamFunction parameter index out of range."); } auto it = std::find_if(m_ties.begin(), m_ties.end(), ReferenceEqual(i)); if (it != m_ties.end()) { delete *it; m_ties.erase(it); unfix(i); return true; } return false; }
ikptr ikrt_make_code(ikptr codesizeptr, ikptr freevars, ikptr rvec, ikpcb* pcb){ assert((fx_mask & (int)codesizeptr) == 0); long int code_size = unfix(codesizeptr); long int memreq = align_to_next_page(code_size + disp_code_data); ikptr mem = ik_mmap_code(memreq, 0, pcb); bzero((char*)(long)mem, memreq); ref(mem, 0) = code_tag; ref(mem, disp_code_code_size) = codesizeptr; ref(mem, disp_code_freevars) = freevars; ref(mem, disp_code_reloc_vector) = rvec; ref(mem, disp_code_annotation) = false_object; ik_relocate_code(mem); return mem+vector_tag; }
int ik_signal_code_to_num(ikptr sigcode){ signal_info* si; int i; for(i=0; i < signal_info_table_len; i++){ si = &signal_info_table[i]; if(si->c == sigcode){ return si->n; } } fprintf(stderr, "ik_signal_code_to_num: Don't know code %ld\n", unfix(sigcode)); exit(EXIT_FAILURE); return 0; }
not used ikptr ikrt_getsockname(ikptr s, ikpcb* pcb){ socklen_t size = sizeof(struct sockaddr); ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data+size)) + bytevector_tag; int r = getsockname(unfix(s), (struct sockaddr*)(bv+off_bytevector_data), &size); if(r == 0){ ref(bv, off_bytevector_length) = fix(size); return bv; } else { return ik_errno_to_code(); } }
w_rc_t fixable_page_h::fix_nonroot(const fixable_page_h &parent, PageID shpid, latch_mode_t mode, bool conditional, bool virgin_page) { w_assert1(parent.is_fixed()); w_assert1(mode != LATCH_NL); unfix(); W_DO(smlevel_0::bf->fix_nonroot(_pp, parent._pp, shpid, mode, conditional, virgin_page)); w_assert1(bf_tree_m::is_swizzled_pointer(shpid) || smlevel_0::bf->get_cb(_pp)->_pid == shpid); _bufferpool_managed = true; _mode = mode; return RCOK; }
static void scheme_to_ffi_record_value_cast(ffi_type* t, ikptr nptr, ikptr p, void* r) { if (t->type != FFI_TYPE_STRUCT) { fprintf(stderr, "not a struct type\n"); exit(-1); } ffi_type** ts = t->elements; char* buf = r; ikptr lenptr = ref(nptr, off_vector_length); int n = unfix(lenptr); int i; for(i=0; i<n; i++) { ffi_type* at = ts[i]; ikptr argt = ref(nptr, off_vector_data + i*wordsize); ikptr arg = ref(p, off_vector_data + i*wordsize); scheme_to_ffi_value_cast(at, argt, arg, buf); buf += at->size; } }
ikptr ikrt_bvftime(ikptr outbv, ikptr fmtbv){ time_t t; struct tm* tmp; t = time(NULL); tmp = localtime(&t); if(tmp == NULL){ fprintf(stderr, "Error in time: %s\n", strerror(errno)); } int rv = strftime((char*)(long)(outbv+off_bytevector_data), unfix(ref(outbv, off_bytevector_length)) + 1, (char*)(long)(fmtbv+off_bytevector_data), tmp); if(rv == 0){ fprintf(stderr, "Error in strftime: %s\n", strerror(errno)); } return fix(rv); }
static ffi_type* scheme_to_ffi_record_type_cast(ikptr vec){ ikptr lenptr = ref(vec, -vector_tag); if (! is_fixnum(lenptr)) { fprintf(stderr, "NOT A VECTOR 0x%016lx\n", vec); exit(-1); } long n = unfix(lenptr); ffi_type* t = alloc(sizeof(ffi_type), 1); ffi_type** ts = alloc(sizeof(ffi_type*), n+1); t->size = 0; t->alignment = 0; t->type = FFI_TYPE_STRUCT; t->elements = ts; long i; for(i=0; i<n; i++){ ts[i] = scheme_to_ffi_type_cast(ref(vec, off_vector_data + i*wordsize)); } ts[n] = 0; return t; }
static void scheme_to_ffi_value_cast(ffi_type* t, ikptr nptr, ikptr p, void* r) { if (tagof(nptr) == vector_tag) { scheme_to_ffi_record_value_cast(t, nptr, p, r); } else if (is_fixnum(nptr)) { long n = unfix(nptr); switch (n & 0xF) { case 1: { return; } case 2: // ffi_type_uint8; case 3: { *((char*)r) = extract_num(p); return; } case 4: // ffi_type_uint16; case 5: { *((short*)r) = extract_num(p); return; } case 6: // ffi_type_uint32; case 7: { *((int*)r) = extract_num(p); return; } case 8: // ffi_type_uint64; case 9: { *((long*)r) = extract_num(p); return; } case 10: case 11: { *((long long*)r) = extract_num_longlong(p); return; } case 12: //return &ffi_type_float; { *((float*)r) = flonum_data(p); return; } case 13: //return &ffi_type_double; { *((double*)r) = flonum_data(p); return; } case 14: //return &ffi_type_pointer; { *((void**)r) = (void*)ref(p, off_pointer_data); return; } default: fprintf(stderr, "INVALID ARG %ld", n); exit(-1); } } else { fprintf(stderr, "INVALID TYPE 0x%016lx\n", nptr); exit(-1); } }
ikptr ikrt_ffi_prep_cif(ikptr rtptr, ikptr argstptr, ikpcb* pcb) { ffi_cif* cif = alloc(sizeof(ffi_cif), 1); ffi_abi abi = FFI_DEFAULT_ABI; int nargs = unfix(ref(argstptr, off_vector_length)); ffi_type** argtypes = alloc(sizeof(ffi_type*), nargs+1); int i; for(i=0; i<nargs; i++){ ikptr argt = ref(argstptr, off_vector_data + i*wordsize); argtypes[i] = scheme_to_ffi_type_cast(argt); } argtypes[nargs] = NULL; ffi_type* rtype = scheme_to_ffi_type_cast(rtptr); ffi_status s = ffi_prep_cif(cif, abi, nargs, rtype, argtypes); if (s == FFI_OK) { ikptr r = ik_safe_alloc(pcb, pointer_size); ref(r, 0) = pointer_tag; ref(r, wordsize) = (ikptr)cif; return r + vector_tag; } else { return false_object; } }