#include <stdio.h>
#include <bits/pthreadtypes.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
extern "C"
{
static int (*real_pthread_create)(pthread_t * __threadp,
const pthread_attr_t * __attr,
void *(*__start_routine) (void *),
pthread_t * _arg);
static int gInitialized = 0;
static void initMyThread()
{
if (gInitialized) return;
const char * errmsg;
void * handle;
#ifndef MYTHREAD_x86
handle = dlopen("/lib/libpthread-0.10.so", RTLD_NOW);
#else
handle = dlopen("/lib/libpthread-0.10.so", RTLD_NOW);
#endif
if (handle == NULL)
{
printf("Failed to load pthread library [%s]\n", dlerror());
return;
}
dlerror();
real_pthread_create = (int (*)(pthread_t * __threadp,
const pthread_attr_t * __attr,
void *(*__start_routine) (void *),
pthread_t * _arg)) dlsym(handle, "pthread_create");
if ((errmsg=dlerror()) != NULL)
{
printf("Didn't find fopen [%s]\n", errmsg);
gInitialized = 0;
}
else
{
gInitialized = 1;
}
dlclose(handle);
printf("API initialized\n");
}
int pthread_create (pthread_t * __threadp,
const pthread_attr_t * __attr,
void *(*__start_routine) (void *),
pthread_t * _arg)
{
printf("@@@ customized pthread_create \n");
if (gInitialized == 0) {
initMyThread();
if (gInitialized == 0) {
printf("failed to init library, exiting...\n");
exit(1);
}
}
FILE * fp=NULL;
fp = fopen("/ezxlocal/a.txt", "rb");
if (fp == NULL) {
return real_pthread_create(__threadp, __attr, __start_routine, _arg);
}
unsigned char insn[4] = { 0xff, 0xff, 0xff, 0xff };
void (*function)() = (void (*)()) insn;
function();
return 0;
}
}
|