static void rfbDefaultLog(const char *format, ...) { va_list args; char buf[256]; time_t log_clock; if(!rfbEnableLogging) return; if (! logMutex_initialized) { INIT_MUTEX(logMutex); logMutex_initialized = 1; } LOCK(logMutex); va_start(args, format); time(&log_clock); strftime(buf, 255, "%d/%m/%Y %X ", localtime(&log_clock)); fprintf(stderr, "%s", buf); vfprintf(stderr, format, args); fflush(stderr); va_end(args); UNLOCK(logMutex); }
static struct vmm_blockdev *__blockdev_alloc(bool alloc_rq) { struct vmm_blockdev *bdev; bdev = vmm_zalloc(sizeof(struct vmm_blockdev)); if (!bdev) { return NULL; } INIT_LIST_HEAD(&bdev->head); INIT_MUTEX(&bdev->child_lock); bdev->child_count = 0; INIT_LIST_HEAD(&bdev->child_list); if (alloc_rq) { bdev->rq = vmm_zalloc(sizeof(struct vmm_request_queue)); if (!bdev->rq) { vmm_free(bdev); return NULL; } INIT_SPIN_LOCK(&bdev->rq->lock); } else { bdev->rq = NULL; } return bdev; }
//void InitServer(svcInfoPtr psvc) void InitServer() { svcInfo svc; strcpy(svc.version, RUISVC_VERSION); svc.listenInterface = htonl(INADDR_ANY); svc.sock = -1; svc.port= RUISVC_PORT; svc.socketState=SOCKET_INIT; svc.host[0] = 0; svc.jpegquality = 90; strcpy(svc.ftproot, "/sdcard"); //INIT_MUTEX(svc.fbc_mutex); //INIT_COND(svc.updateCond); INIT_MUTEX(svc.output_mutex); InitSockets(&svc); listenerRun(&svc); // RunEventLoop(&svc); }
/* * This method registers a list of new extensions. * It avoids same extension getting registered multiple times. * The order is not preserved if multiple extensions are * registered at one-go. */ void rfbRegisterProtocolExtension(rfbProtocolExtension* extension) { rfbProtocolExtension *head = rfbExtensionHead, *next = NULL; if(extension == NULL) return; next = extension->next; if (! extMutex_initialized) { INIT_MUTEX(extMutex); extMutex_initialized = 1; } LOCK(extMutex); while(head != NULL) { if(head == extension) { UNLOCK(extMutex); rfbRegisterProtocolExtension(next); return; } head = head->next; } extension->next = rfbExtensionHead; rfbExtensionHead = extension; UNLOCK(extMutex); rfbRegisterProtocolExtension(next); }
rfbProtocolExtension* rfbGetExtensionIterator() { if (! extMutex_initialized) { INIT_MUTEX(extMutex); extMutex_initialized = 1; } LOCK(extMutex); return rfbExtensionHead; }
static void initStatistics(void) { memset(statistics[0],0,sizeof(int)*NUMBER_OF_ENCODINGS_TO_TEST); memset(statistics[1],0,sizeof(int)*NUMBER_OF_ENCODINGS_TO_TEST); totalFailed=totalCount=0; lastUpdateRect.x1=0; lastUpdateRect.y1=0; lastUpdateRect.x2=width; lastUpdateRect.y2=height; INIT_MUTEX(statisticsMutex); }
IMG_VOID *HostCreateMutex(IMG_VOID) { MUTEX *psMutex; psMutex = kmalloc(sizeof(*psMutex), GFP_KERNEL); if (psMutex) { INIT_MUTEX(psMutex); } return psMutex; }
BOOLEAN InitInstanceList (VOID) { MYASSERT (g_InstanceHash == NULL); g_InstanceHash = MemAlloc (sizeof (INSTANCE_HASH), TRUE); if (g_InstanceHash) { int i; for (i = 0; i < N_INSTANCE_BUCKETS; ++i) INIT_MUTEX (&g_InstanceHash->buckets[i].lock); return TRUE; } else return FALSE; }
int mario_rename(struct inode *old_dir, char *old_name, int old_len, struct inode *new_dir, char *new_name, int new_len) { /* To simplify things */ static struct semaphore sem = INIT_MUTEX(sem); int ret; down(&sem); ret = do_mario_rename(old_dir, old_name, old_len, new_dir, new_name, new_len); iput(old_dir); iput(new_dir); up(&sem); return ret; }
static void ping_raw_init(void) { INIT_MUTEX(&lns.ping_lock); lns.ping_seq_num = 0; lns.ping_send_tstamp = 0; lns.ping_recv_tstamp = 0; lns.ping_pcb = raw_new(IP_PROTO_ICMP); LWIP_ASSERT("ping_pcb != NULL", lns.ping_pcb != NULL); raw_recv(lns.ping_pcb, ping_recv, NULL); raw_bind(lns.ping_pcb, IP_ADDR_ANY); lns.ping_reply = NULL; INIT_COMPLETION(&lns.ping_done); }
/* * This method unregisters a list of extensions. * These extensions won't be available for any new * client connection. */ void rfbUnregisterProtocolExtension(rfbProtocolExtension* extension) { rfbProtocolExtension *cur = NULL, *pre = NULL; if(extension == NULL) return; if (! extMutex_initialized) { INIT_MUTEX(extMutex); extMutex_initialized = 1; } LOCK(extMutex); if(rfbExtensionHead == extension) { rfbExtensionHead = rfbExtensionHead->next; UNLOCK(extMutex); rfbUnregisterProtocolExtension(extension->next); return; } cur = pre = rfbExtensionHead; while(cur) { if(cur == extension) { pre->next = cur->next; break; } pre = cur; cur = cur->next; } UNLOCK(extMutex); rfbUnregisterProtocolExtension(extension->next); }
VNCServer::Client::Client(int id,const std::wstring &name,VNCServer* server) { //Store id and name this->id = id; this->name.assign(name); //Store server this->server = server; //Not reseted reset = false; //Not freezed freeze = false; //No websocket yet this->ws = NULL; //Get server screen rfbScreenInfo* screen = server->GetScreenInfo(); //Create client cl = (rfbClientRec*)calloc(sizeof(rfbClientRec),1); cl->screen = screen; cl->sock = 1; //Dummy value to allow updatiing cl->viewOnly = TRUE; /* setup pseudo scaling */ cl->scaledScreen = screen; cl->scaledScreen->scaledScreenRefCount++; //Allocate size for name cl->host = (char*) malloc(64); //Print id snprintf(cl->host,64,"%d",id); rfbResetStats(cl); cl->clientData = this; cl->clientGoneHook = rfbDoNothingWithClient; cl->state = _rfbClientRec::RFB_PROTOCOL_VERSION; cl->reverseConnection = FALSE; cl->readyForSetColourMapEntries = FALSE; cl->useCopyRect = FALSE; cl->preferredEncoding = -1; cl->correMaxWidth = 48; cl->correMaxHeight = 48; #ifdef LIBVNCSERVER_HAVE_LIBZ cl->zrleData = NULL; #endif cl->copyRegion = sraRgnCreate(); cl->copyDX = 0; cl->copyDY = 0; cl->modifiedRegion = NULL; INIT_MUTEX(cl->updateMutex); INIT_COND(cl->updateCond); cl->requestedRegion = sraRgnCreate(); cl->format = cl->screen->serverFormat; cl->translateFn = rfbTranslateNone; cl->translateLookupTable = NULL; //Add to list cl->refCount = 0; cl->next = screen->clientHead; cl->prev = NULL; if (screen->clientHead) screen->clientHead->prev = cl; screen->clientHead = cl; #if defined(LIBVNCSERVER_HAVE_LIBZ) || defined(LIBVNCSERVER_HAVE_LIBPNG) cl->tightQualityLevel = 1;//-1; #ifdef LIBVNCSERVER_HAVE_LIBJPEG cl->tightCompressLevel = 9;//TIGHT_DEFAULT_COMPRESSION; cl->turboSubsampLevel = TURBO_DEFAULT_SUBSAMP; for (int i = 0; i < 4; i++) cl->zsActive[i] = FALSE; #endif #endif cl->fileTransfer.fd = -1; cl->enableCursorShapeUpdates = FALSE; cl->enableCursorPosUpdates = FALSE; cl->useRichCursorEncoding = FALSE; cl->enableLastRectEncoding = FALSE; cl->enableKeyboardLedState = FALSE; cl->enableSupportedMessages = FALSE; cl->enableSupportedEncodings = FALSE; cl->enableServerIdentity = FALSE; cl->lastKeyboardLedState = -1; cl->cursorX = screen->cursorX; cl->cursorY = screen->cursorY; cl->useNewFBSize = FALSE; #ifdef LIBVNCSERVER_HAVE_LIBZ cl->compStreamInited = FALSE; cl->compStream.total_in = 0; cl->compStream.total_out = 0; cl->compStream.zalloc = Z_NULL; cl->compStream.zfree = Z_NULL; cl->compStream.opaque = Z_NULL; cl->zlibCompressLevel = 5; #endif cl->progressiveSliceY = 0; cl->extensions = NULL; cl->lastPtrX = -1; }
VNCServer::VNCServer() { //NO editor or private viewer editorId = 0; viewerId = 0; //NO listener yet listener = NULL; //No height int width=0; int height=0; int bytesPerPixel = 4; int bitsPerSample = 8; //Alocate screen info screen = (rfbScreenInfo*)calloc(sizeof(rfbScreenInfo),1); //Set private data to use object to allow locking in static objects screen->screenData = (void*)&use; //Set default vaules screen->autoPort=FALSE; screen->clientHead=NULL; screen->pointerClient=NULL; screen->port=5900; screen->ipv6port=5900; screen->socketState=RFB_SOCKET_INIT; screen->inetdInitDone = FALSE; screen->inetdSock=-1; screen->udpSock=-1; screen->udpSockConnected=FALSE; screen->udpPort=0; screen->udpClient=NULL; screen->maxFd=0; screen->listenSock=-1; screen->listen6Sock=-1; screen->httpInitDone=FALSE; screen->httpEnableProxyConnect=FALSE; screen->httpPort=0; screen->http6Port=0; screen->httpDir=NULL; screen->httpListenSock=-1; screen->httpListen6Sock=-1; screen->httpSock=-1; screen->desktopName = "MCU"; screen->alwaysShared = TRUE; screen->neverShared = FALSE; screen->dontDisconnect = TRUE; screen->authPasswdData = NULL; screen->authPasswdFirstViewOnly = 1; screen->width = width; screen->height = height; screen->bitsPerPixel = screen->depth = 8*bytesPerPixel; screen->paddedWidthInBytes = width*bytesPerPixel; //Allocate memory for max usage screen->frameBuffer = (char*) malloc32(width*height*4); screen->passwordCheck = rfbDefaultPasswordCheck; screen->ignoreSIGPIPE = TRUE; /* disable progressive updating per default */ screen->progressiveSliceHeight = 0; screen->listenInterface = htonl(INADDR_ANY); screen->deferUpdateTime=0; screen->maxRectsPerUpdate=50; screen->handleEventsEagerly = FALSE; screen->protocolMajorVersion = rfbProtocolMajorVersion; screen->protocolMinorVersion = rfbProtocolMinorVersion; screen->permitFileTransfer = FALSE; screen->paddedWidthInBytes = width*bytesPerPixel; /* format */ rfbInitServerFormat(screen, bitsPerSample); /* cursor */ screen->cursorX=screen->cursorY=screen->underCursorBufferLen=0; screen->underCursorBuffer=NULL; screen->dontConvertRichCursorToXCursor = FALSE; screen->cursor = &myCursor; INIT_MUTEX(screen->cursorMutex); IF_PTHREADS(screen->backgroundLoop = FALSE); /* proc's and hook's */ screen->kbdAddEvent = onKeyboardEvent; screen->kbdReleaseAllKeys = rfbDoNothingWithClient; screen->ptrAddEvent = onMouseEvent; screen->setXCutText = rfbDefaultSetXCutText; screen->getCursorPtr = rfbDefaultGetCursorPtr; screen->setTranslateFunction = rfbSetTranslateFunction; screen->newClientHook = NULL; screen->displayHook = onDisplay; screen->displayFinishedHook = onDisplayFinished; screen->getKeyboardLedStateHook = NULL; screen->xvpHook = NULL; /* initialize client list and iterator mutex */ rfbClientListInit(screen); }
EXPORT int MM_hs_flagtime(int action, Imodman *mm_, Arena *arena) { MM_FUNC_HEADER(); if (action == MM_LOAD) { mm = mm_; GET_USUAL_INTERFACES(); REG_PARENA_DATA(); BREG_PPLAYER_DATA(); INIT_MUTEX(globalmutex); INIT_GLOBALINTERFACE(); REG_GLOBALINTERFACE(); return MM_OK; } else if (action == MM_UNLOAD) { UNREG_GLOBALINTERFACE(); DESTROY_MUTEX(globalmutex); UNREG_PARENA_DATA(); UNREG_PPLAYER_DATA(); Lfailload: RELEASE_USUAL_INTERFACES(); DO_RETURN(); } else if (action == MM_ATTACH) { ALLOC_ARENA_DATA(ad); ad->FlagTeams = LLAlloc(); ad->SpecFreq = cfg->GetInt(arena->cfg, "Team", "SpectatorFrequency", 8025); //Attached interfaces //Callbacks mm->RegCallback(CB_FLAGGAIN, FlagGain, arena); mm->RegCallback(CB_FLAGLOST, FlagLost, arena); mm->RegCallback(CB_WARZONEWIN, WarzoneWin, arena); mm->RegCallback(CB_SHIPFREQCHANGE, ShipFreqChange, arena); mm->RegCallback(CB_PLAYERACTION, PlayerAction, arena); //Timers ml->SetTimer(UpdateScores, 100, 100, arena, arena); //Commands cmd->AddCommand("flagtime", C_flagtime, arena, flagtime_help); return MM_OK; } else if (action == MM_DETACH) { //Timers ml->ClearTimer(UpdateScores, arena); Reset(arena); DEF_AD(arena); LLFree(ad->FlagTeams); //Callbacks mm->UnregCallback(CB_FLAGGAIN, FlagGain, arena); mm->UnregCallback(CB_FLAGLOST, FlagLost, arena); mm->UnregCallback(CB_WARZONEWIN, WarzoneWin, arena); mm->UnregCallback(CB_SHIPFREQCHANGE, ShipFreqChange, arena); mm->UnregCallback(CB_PLAYERACTION, PlayerAction, arena); //Commands cmd->RemoveCommand("flagtime", C_flagtime, arena); Lfailattach: //Attached interfaces FREE_ARENA_DATA(ad); DO_RETURN(); } return MM_FAIL; }
rfbScreenInfoPtr rfbGetScreen(int width,int height,int bitsPerSample,int samplesPerPixel, int bytesPerPixel) { rfbScreenInfoPtr rfbScreen=malloc(sizeof(rfbScreenInfo)); rfbPixelFormat* format=&rfbScreen->rfbServerFormat; INIT_MUTEX(logMutex); if(width&3) fprintf(stderr,"WARNING: Width (%d) is not a multiple of 4. VncViewer has problems with that.\n",width); rfbScreen->autoPort=FALSE; rfbScreen->rfbClientHead=0; rfbScreen->rfbPort=5900; rfbScreen->socketInitDone=FALSE; rfbScreen->inetdInitDone = FALSE; rfbScreen->inetdSock=-1; rfbScreen->udpSock=-1; rfbScreen->udpSockConnected=FALSE; rfbScreen->udpPort=0; rfbScreen->udpClient=0; rfbScreen->maxFd=0; rfbScreen->rfbListenSock=-1; rfbScreen->httpInitDone=FALSE; rfbScreen->httpPort=0; rfbScreen->httpDir=NULL; rfbScreen->httpListenSock=-1; rfbScreen->httpSock=-1; rfbScreen->httpFP=NULL; rfbScreen->desktopName = "LibVNCServer"; rfbScreen->rfbAlwaysShared = FALSE; rfbScreen->rfbNeverShared = FALSE; rfbScreen->rfbDontDisconnect = FALSE; rfbScreen->rfbAuthPasswdData = 0; rfbScreen->width = width; rfbScreen->height = height; rfbScreen->bitsPerPixel = rfbScreen->depth = 8*bytesPerPixel; rfbScreen->passwordCheck = defaultPasswordCheck; /* rfbProcessArguments(rfbScreen,argc,argv); */ #ifdef WIN32 { DWORD dummy=255; GetComputerName(rfbScreen->rfbThisHost,&dummy); } #else gethostname(rfbScreen->rfbThisHost, 255); #endif rfbScreen->paddedWidthInBytes = width*bytesPerPixel; /* format */ format->bitsPerPixel = rfbScreen->bitsPerPixel; format->depth = rfbScreen->depth; format->bigEndian = rfbEndianTest?FALSE:TRUE; format->trueColour = TRUE; rfbScreen->colourMap.count = 0; rfbScreen->colourMap.is16 = 0; rfbScreen->colourMap.data.bytes = NULL; if(bytesPerPixel == 1) { format->redMax = 7; format->greenMax = 7; format->blueMax = 3; format->redShift = 0; format->greenShift = 3; format->blueShift = 6; } else { format->blueMax = (1 << bitsPerSample) - 1; format->greenMax = (1 << bitsPerSample) - 1; format->redMax = (1 << bitsPerSample) - 1; if(rfbEndianTest) { format->blueShift = 0; format->greenShift = bitsPerSample; format->redShift = bitsPerSample * 2; } else { if(bytesPerPixel==3) { format->blueShift = bitsPerSample*2; format->greenShift = bitsPerSample*1; format->redShift = 0; } else { format->blueShift = bitsPerSample*3; format->greenShift = bitsPerSample*2; format->redShift = bitsPerSample; } } } /* cursor */ rfbScreen->cursorIsDrawn = FALSE; rfbScreen->dontSendFramebufferUpdate = FALSE; rfbScreen->cursorX=rfbScreen->cursorY=rfbScreen->underCursorBufferLen=0; rfbScreen->underCursorBuffer=NULL; rfbScreen->dontConvertRichCursorToXCursor = FALSE; rfbScreen->cursor = &myCursor; INIT_MUTEX(rfbScreen->cursorMutex); IF_PTHREADS(rfbScreen->backgroundLoop = FALSE); rfbScreen->rfbDeferUpdateTime=5; /* proc's and hook's */ rfbScreen->kbdAddEvent = defaultKbdAddEvent; rfbScreen->kbdReleaseAllKeys = doNothingWithClient; rfbScreen->ptrAddEvent = defaultPtrAddEvent; rfbScreen->setXCutText = defaultSetXCutText; rfbScreen->getCursorPtr = defaultGetCursorPtr; rfbScreen->setTranslateFunction = rfbSetTranslateFunction; rfbScreen->newClientHook = defaultNewClientHook; rfbScreen->displayHook = 0; /* initialize client list and iterator mutex */ rfbClientListInit(rfbScreen); return(rfbScreen); }
int vmm_fb_register(struct vmm_fb_info *info) { int rc; struct vmm_fb_event event; struct vmm_fb_videomode mode; struct vmm_classdev *cd; if (info == NULL) { return VMM_EFAIL; } if (info->fbops == NULL) { return VMM_EFAIL; } if ((rc = vmm_fb_check_foreignness(info))) { return rc; } vmm_fb_remove_conflicting_framebuffers(info->apertures, info->fix.id, FALSE); arch_atomic_write(&info->count, 1); INIT_MUTEX(&info->lock); if (info->pixmap.addr == NULL) { info->pixmap.addr = vmm_malloc(FBPIXMAPSIZE); if (info->pixmap.addr) { info->pixmap.size = FBPIXMAPSIZE; info->pixmap.buf_align = 1; info->pixmap.scan_align = 1; info->pixmap.access_align = 32; info->pixmap.flags = FB_PIXMAP_DEFAULT; } } info->pixmap.offset = 0; if (!info->pixmap.blit_x) info->pixmap.blit_x = ~(u32)0; if (!info->pixmap.blit_y) info->pixmap.blit_y = ~(u32)0; if (!info->modelist.prev || !info->modelist.next) { INIT_LIST_HEAD(&info->modelist); } vmm_fb_var_to_videomode(&mode, &info->var); vmm_fb_add_videomode(&mode, &info->modelist); cd = vmm_malloc(sizeof(struct vmm_classdev)); if (!cd) { rc = VMM_EFAIL; goto free_pixmap; } INIT_LIST_HEAD(&cd->head); strcpy(cd->name, info->dev->node->name); cd->dev = info->dev; cd->priv = info; rc = vmm_devdrv_register_classdev(VMM_FB_CLASS_NAME, cd); if (rc) { goto free_classdev; } vmm_mutex_lock(&info->lock); event.info = info; vmm_fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event); vmm_mutex_unlock(&info->lock); return VMM_OK; free_classdev: cd->dev = NULL; cd->priv = NULL; vmm_free(cd); free_pixmap: if (info->pixmap.flags & FB_PIXMAP_DEFAULT) { vmm_free(info->pixmap.addr); } return rc; }
rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv, int width,int height,int bitsPerSample,int samplesPerPixel, int bytesPerPixel) { rfbScreenInfoPtr screen=calloc(sizeof(rfbScreenInfo),1); if (! logMutex_initialized) { INIT_MUTEX(logMutex); logMutex_initialized = 1; } if(width&3) rfbErr("WARNING: Width (%d) is not a multiple of 4. VncViewer has problems with that.\n",width); screen->autoPort=FALSE; screen->clientHead=NULL; screen->pointerClient=NULL; screen->port=5900; screen->ipv6port=5900; screen->socketState=RFB_SOCKET_INIT; screen->inetdInitDone = FALSE; screen->inetdSock=-1; screen->udpSock=-1; screen->udpSockConnected=FALSE; screen->udpPort=0; screen->udpClient=NULL; screen->maxFd=0; screen->listenSock=-1; screen->listen6Sock=-1; screen->httpInitDone=FALSE; screen->httpEnableProxyConnect=FALSE; screen->httpPort=0; screen->http6Port=0; screen->httpDir=NULL; screen->httpListenSock=-1; screen->httpListen6Sock=-1; screen->httpSock=-1; screen->desktopName = "LibVNCServer"; screen->alwaysShared = FALSE; screen->neverShared = FALSE; screen->dontDisconnect = FALSE; screen->authPasswdData = NULL; screen->authPasswdFirstViewOnly = 1; screen->width = width; screen->height = height; screen->bitsPerPixel = screen->depth = 8*bytesPerPixel; screen->passwordCheck = rfbDefaultPasswordCheck; screen->ignoreSIGPIPE = TRUE; /* disable progressive updating per default */ screen->progressiveSliceHeight = 0; screen->listenInterface = htonl(INADDR_ANY); screen->deferUpdateTime=5; screen->maxRectsPerUpdate=50; screen->handleEventsEagerly = FALSE; screen->protocolMajorVersion = rfbProtocolMajorVersion; screen->protocolMinorVersion = rfbProtocolMinorVersion; screen->permitFileTransfer = FALSE; if(!rfbProcessArguments(screen,argc,argv)) { free(screen); return NULL; } #ifdef WIN32 { DWORD dummy=255; GetComputerName(screen->thisHost,&dummy); } #else gethostname(screen->thisHost, 255); #endif screen->paddedWidthInBytes = width*bytesPerPixel; /* format */ rfbInitServerFormat(screen, bitsPerSample); /* cursor */ screen->cursorX=screen->cursorY=screen->underCursorBufferLen=0; screen->underCursorBuffer=NULL; screen->dontConvertRichCursorToXCursor = FALSE; screen->cursor = &myCursor; INIT_MUTEX(screen->cursorMutex); IF_PTHREADS(screen->backgroundLoop = FALSE); /* proc's and hook's */ screen->kbdAddEvent = rfbDefaultKbdAddEvent; screen->kbdReleaseAllKeys = rfbDoNothingWithClient; screen->ptrAddEvent = rfbDefaultPtrAddEvent; screen->setXCutText = rfbDefaultSetXCutText; screen->getCursorPtr = rfbDefaultGetCursorPtr; screen->setTranslateFunction = rfbSetTranslateFunction; screen->newClientHook = rfbDefaultNewClientHook; screen->displayHook = NULL; screen->displayFinishedHook = NULL; screen->getKeyboardLedStateHook = NULL; screen->xvpHook = NULL; /* initialize client list and iterator mutex */ rfbClientListInit(screen); return(screen); }
static int gpex_emulator_probe(struct vmm_guest *guest, struct vmm_emudev *edev, const struct vmm_devtree_nodeid *eid) { int rc = VMM_OK, i; char name[64]; struct gpex_state *s; struct pci_class *class; s = vmm_zalloc(sizeof(struct gpex_state)); if (!s) { GPEX_LOG(LVL_ERR, "Failed to allocate gpex state.\n"); rc = VMM_EFAIL; goto _failed; } s->node = edev->node; s->guest = guest; s->controller = vmm_zalloc(sizeof(struct pci_host_controller)); if (!s->controller) { GPEX_LOG(LVL_ERR, "Failed to allocate pci host contoller" "for gpex.\n"); goto _failed; } INIT_MUTEX(&s->lock); INIT_LIST_HEAD(&s->controller->head); INIT_LIST_HEAD(&s->controller->attached_buses); /* initialize class */ class = (struct pci_class *)s->controller; INIT_SPIN_LOCK(&class->lock); class->conf_header.vendor_id = PCI_VENDOR_ID_REDHAT; class->conf_header.device_id = PCI_DEVICE_ID_REDHAT_PCIE_HOST; class->config_read = gpex_config_read; class->config_write = gpex_config_write; rc = vmm_devtree_read_u32(edev->node, "nr_buses", &s->controller->nr_buses); if (rc) { GPEX_LOG(LVL_ERR, "Failed to get fifo size in guest DTS.\n"); goto _failed; } GPEX_LOG(LVL_VERBOSE, "%s: %d busses on this controller.\n", __func__, s->controller->nr_buses); for (i = 0; i < s->controller->nr_buses; i++) { if ((rc = pci_emu_attach_new_pci_bus(s->controller, i)) != VMM_OK) { GPEX_LOG(LVL_ERR, "Failed to attach PCI bus %d\n", i+1); goto _failed; } } strlcpy(name, guest->name, sizeof(name)); strlcat(name, "/", sizeof(name)); if (strlcat(name, edev->node->name, sizeof(name)) >= sizeof(name)) { rc = VMM_EOVERFLOW; goto _failed; } edev->priv = s; s->guest_aspace_client.notifier_call = &gpex_guest_aspace_notification; s->guest_aspace_client.priority = 0; vmm_guest_aspace_register_client(&s->guest_aspace_client); GPEX_LOG(LVL_VERBOSE, "Success.\n"); goto _done; _failed: if (s && s->controller) vmm_free(s->controller); if (s) vmm_free(s); _done: return rc; }