ATerm SSL_gtr(ATerm x, ATerm y) { assert_is_real(x); assert_is_real(y); if(_get_real(x) > _get_real(y)) return((ATerm) ATempty); else _fail((ATerm) ATempty); return((ATerm) ATempty); }
static void _enable_thread_support(const char *call) { UNUSED(call); //fprintf(stderr, "NEW THREAD!\n"); // Thread interfaces may be in libc.so or in a different library // such as libpthread.so, and thus they are not automatically // available to all programs. We want to handle threading // (synchronize access to static data, track thread creation, // report thread ids in threaded programs, etc) without // opening Pandora's box for single-threaded programs. Thus // we initialize these pointers only if we got here, a clear // indication of a threaded program. They'll be available // for subsequent use iff they're non-null. if (!pthread_mutex_lock_real) { // We can be pretty sure this will only be executed once, // just prior to the first thread creation (which will actually // create thread #2 since the main thread is always #1). pthread_mutex_lock_real = _get_real("pthread_mutex_lock"); pthread_mutex_unlock_real = _get_real("pthread_mutex_unlock"); pthread_self_real = _get_real("pthread_self"); } }
/// Interposes over the creat64() function. /// @param[in] call the name of the interposed function in string form /// @param[in] next a pointer to the interposed function /// @param[in] path same as the wrapped function /// @param[in] mode same as the wrapped function /// @return same as the wrapped function /*static*/ int creat64_wrapper(const char *call, int (*next) (const char *, mode_t), const char *path, mode_t mode) { int oflag; static int (*open64_real) (const char *, int, ...); WRAPPER_DEBUG("ENTERING creat64_wrapper() => %p [%s ...]\n", next, path); if (!open64_real) { open64_real = (int (*)(const char *, int, ...))_get_real("open64"); } UNUSED(next); oflag = O_WRONLY | O_CREAT | O_TRUNC; return open64_wrapper(call, open64_real, path, oflag, mode); }
static int x__close(int fd) { static int (*next) (int); const char *funcname = "close"; pthread_t tid; if (!next) { next = _get_real(funcname); } tid = pthread_self_real(); if (tid == tidopener) { fprintf(stderr, "= close(%d)\n", fd); } return next (fd); }
static int x__open(const char *path, int oflag, ...) { static int (*next) (const char *, int, ...); mode_t mode = 0; if (!next) { next = _get_real("open"); } if (oflag & O_CREAT) { va_list ap; va_start(ap, oflag); mode = va_arg(ap, int); /* NOT mode_t */ va_end(ap); } else {
/// This function will be called at the <i>earliest possible /// opportunity</i> once the audited command is fully initialized /// and running. This generally means at the first interposed /// function called after main(). We would love to figure out a /// way to get earlier, e.g. to interpose on main() itself, but /// for now this is the best we have and it seems to work fine. /// @param[in] call the name of the interposed function call /*static*/ void interposed_late_init(const char *call) { const char *exe; unsigned long pid; // Must be done before putenv() is called as that could // realloc the 'environ' pointer away from argv. exe = putil_prog(); // Certain libc functions must be called from within this library. // We need the real semantics; wrappers are apt to get into loops. // *INDENT-OFF* fopen_real = (FILE *(*)(const char *, const char *))_get_real("fopen"); fork_real = (pid_t(*)(void))_get_real("fork"); open_real = (int(*)(const char *, int, ...))_get_real("open"); close_real = (int(*)(int))_get_real("close"); rename_real = (int(*)(const char *, const char *))_get_real("rename"); link_real = (int(*)(const char *, const char *))_get_real("link"); symlink_real = (int(*)(const char *, const char *))_get_real("symlink"); unlink_real = (int(*)(const char *))_get_real("unlink"); _exit_real = (void(*)(int))_get_real("_exit"); // *INDENT-ON* if ((pid = _init_auditlib(call, exe, interposer_get_cmdline()))) { // Put the pid of the *current* process into the env block as the // *parent* cmd id. if (prop_has_value(P_PCMDID)) { prop_mod_ulong(P_PCMDID, pid, NULL); } // Turn on the auditor and go. interposer_set_active(1); } else { interposer_set_active(0); } }
ATerm SSL_modr(ATerm x, ATerm y) { assert_is_real(x); assert_is_real(y); return((ATerm) ATmakeReal(fmod(_get_real(x), _get_real(y)))); }
ATerm SSL_divr(ATerm x, ATerm y) { assert_is_real(x); assert_is_real(y); return((ATerm) ATmakeReal(_get_real(x) / _get_real(y))); }