/** * @interface_method_impl{TXSTRANSPORT,pfnOption} */ static DECLCALLBACK(int) txsTcpOption(int ch, PCRTGETOPTUNION pVal) { int rc; switch (ch) { case TXSTCPOPT_MODE: if (!strcmp(pVal->psz, "both")) g_enmTcpMode = TXSTCPMODE_BOTH; else if (!strcmp(pVal->psz, "client")) g_enmTcpMode = TXSTCPMODE_CLIENT; else if (!strcmp(pVal->psz, "server")) g_enmTcpMode = TXSTCPMODE_SERVER; else return RTMsgErrorRc(VERR_INVALID_PARAMETER, "Invalid TCP mode: '%s'\n", pVal->psz); break; case TXSTCPOPT_BIND_ADDRESS: rc = RTStrCopy(g_szTcpBindAddr, sizeof(g_szTcpBindAddr), pVal->psz); if (RT_FAILURE(rc)) return RTMsgErrorRc(VERR_INVALID_PARAMETER, "TCP bind address is too long (%Rrc)", rc); return VINF_SUCCESS; case TXSTCPOPT_BIND_PORT: g_uTcpBindPort = pVal->u16 == 0 ? TXS_TCP_DEF_BIND_PORT : pVal->u16; break; case TXSTCPOPT_LEGACY_CONNECT: g_enmTcpMode = TXSTCPMODE_CLIENT; /* fall thru */ case TXSTCPOPT_CONNECT_ADDRESS: rc = RTStrCopy(g_szTcpConnectAddr, sizeof(g_szTcpConnectAddr), pVal->psz); if (RT_FAILURE(rc)) return RTMsgErrorRc(VERR_INVALID_PARAMETER, "TCP connect address is too long (%Rrc)", rc); if (!g_szTcpConnectAddr[0]) strcpy(g_szTcpConnectAddr, TXS_TCP_DEF_CONNECT_ADDRESS); return VINF_SUCCESS; case TXSTCPOPT_CONNECT_PORT: g_uTcpConnectPort = pVal->u16 == 0 ? TXS_TCP_DEF_CONNECT_PORT : pVal->u16; break; case TXSTCPOPT_LEGACY_PORT: if (pVal->u16 == 0) { g_uTcpBindPort = TXS_TCP_DEF_BIND_PORT; g_uTcpConnectPort = TXS_TCP_DEF_CONNECT_PORT; } else { g_uTcpBindPort = pVal->u16; g_uTcpConnectPort = pVal->u16; } return VINF_SUCCESS; } return VERR_TRY_AGAIN; }
/** * Register statistics for the MSRs. * * This must not be called before the MSRs have been finalized and moved to the * hyper heap. * * @returns VBox status code. * @param pVM The cross context VM structure. */ int cpumR3MsrRegStats(PVM pVM) { /* * Global statistics. */ PCPUM pCpum = &pVM->cpum.s; STAM_REL_REG(pVM, &pCpum->cMsrReads, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/Reads", STAMUNIT_OCCURENCES, "All RDMSRs making it to CPUM."); STAM_REL_REG(pVM, &pCpum->cMsrReadsRaiseGp, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/ReadsRaisingGP", STAMUNIT_OCCURENCES, "RDMSR raising #GPs, except unknown MSRs."); STAM_REL_REG(pVM, &pCpum->cMsrReadsUnknown, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/ReadsUnknown", STAMUNIT_OCCURENCES, "RDMSR on unknown MSRs (raises #GP)."); STAM_REL_REG(pVM, &pCpum->cMsrWrites, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/Writes", STAMUNIT_OCCURENCES, "All RDMSRs making it to CPUM."); STAM_REL_REG(pVM, &pCpum->cMsrWritesRaiseGp, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/WritesRaisingGP", STAMUNIT_OCCURENCES, "WRMSR raising #GPs, except unknown MSRs."); STAM_REL_REG(pVM, &pCpum->cMsrWritesToIgnoredBits, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/WritesToIgnoredBits", STAMUNIT_OCCURENCES, "Writing of ignored bits."); STAM_REL_REG(pVM, &pCpum->cMsrWritesUnknown, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/WritesUnknown", STAMUNIT_OCCURENCES, "WRMSR on unknown MSRs (raises #GP)."); # ifdef VBOX_WITH_STATISTICS /* * Per range. */ PCPUMMSRRANGE paRanges = pVM->cpum.s.GuestInfo.paMsrRangesR3; uint32_t cRanges = pVM->cpum.s.GuestInfo.cMsrRanges; for (uint32_t i = 0; i < cRanges; i++) { char szName[160]; ssize_t cchName; if (paRanges[i].uFirst == paRanges[i].uLast) cchName = RTStrPrintf(szName, sizeof(szName), "/CPUM/MSRs/%#010x-%s", paRanges[i].uFirst, paRanges[i].szName); else cchName = RTStrPrintf(szName, sizeof(szName), "/CPUM/MSRs/%#010x-%#010x-%s", paRanges[i].uFirst, paRanges[i].uLast, paRanges[i].szName); RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-reads"); STAMR3Register(pVM, &paRanges[i].cReads, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_OCCURENCES, "RDMSR"); RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-writes"); STAMR3Register(pVM, &paRanges[i].cWrites, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, "WRMSR"); RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-GPs"); STAMR3Register(pVM, &paRanges[i].cGps, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, "#GPs"); RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-ign-bits-writes"); STAMR3Register(pVM, &paRanges[i].cIgnoredBits, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, "WRMSR w/ ignored bits"); } # endif /* VBOX_WITH_STATISTICS */ return VINF_SUCCESS; }
/** * Query the trace configuration specification string. * * @returns VBox status code. * @retval VINF_SUCCESS * @retval VERR_INVALID_VM_HANDLE * @retval VERR_INVALID_POINTER * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. Buffer will be * empty. * @param pVM The cross context VM structure. * @param pszConfig Pointer to the output buffer. * @param cbConfig The size of the output buffer. */ VMMDECL(int) DBGFR3TraceQueryConfig(PVM pVM, char *pszConfig, size_t cbConfig) { VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); AssertPtrReturn(pszConfig, VERR_INVALID_POINTER); if (cbConfig < 1) return VERR_BUFFER_OVERFLOW; *pszConfig = '\0'; if (pVM->hTraceBufR3 == NIL_RTTRACEBUF) return VERR_DBGF_NO_TRACE_BUFFER; int rc = VINF_SUCCESS; uint32_t const fTraceGroups = pVM->aCpus[0].fTraceGroups; if ( fTraceGroups == UINT32_MAX && PDMR3TracingAreAll(pVM, true /*fEnabled*/)) rc = RTStrCopy(pszConfig, cbConfig, "all"); else if ( fTraceGroups == 0 && PDMR3TracingAreAll(pVM, false /*fEnabled*/)) rc = RTStrCopy(pszConfig, cbConfig, "-all"); else { char *pszDst = pszConfig; size_t cbDst = cbConfig; uint32_t i = RT_ELEMENTS(g_aVmmTpGroups); while (i-- > 0) if (g_aVmmTpGroups[i].fMask & fTraceGroups) { size_t cchThis = g_aVmmTpGroups[i].cchName + (pszDst != pszConfig); if (cchThis >= cbDst) { rc = VERR_BUFFER_OVERFLOW; break; } if (pszDst != pszConfig) { *pszDst = ' '; memcpy(pszDst + 1, g_aVmmTpGroups[i].pszName, g_aVmmTpGroups[i].cchName + 1); } else memcpy(pszDst, g_aVmmTpGroups[i].pszName, g_aVmmTpGroups[i].cchName + 1); pszDst += cchThis; cbDst -= cchThis; } if (RT_SUCCESS(rc)) rc = PDMR3TracingQueryConfig(pVM, pszDst, cbDst); } if (RT_FAILURE(rc)) *pszConfig = '\0'; return rc; }
RTDECL(int) RTPathAppPrivateArchTop(char *pszPath, size_t cchPath) { #if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH_TOP) return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH_TOP); #elif !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH) return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH); #elif defined(RT_OS_SOLARIS) return rtPathSolarisArchHack(pszPath, cchPath); #else int rc = RTPathExecDir(pszPath, cchPath); return rc; #endif }
/** * Unregisters a shared module for the VM * * @returns VBox status code. * @param pVM Pointer to the VM. * @param pszModuleName Module name. * @param pszVersion Module version. * @param GCBaseAddr Module base address. * @param cbModule Module size. * * @todo This should be a GMMR3 call. No need to involve GMM here. */ VMMR3DECL(int) PGMR3SharedModuleUnregister(PVM pVM, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule) { Log(("PGMR3SharedModuleUnregister name=%s version=%s base=%RGv size=%x\n", pszModuleName, pszVersion, GCBaseAddr, cbModule)); AssertMsgReturn(cbModule > 0 && cbModule < _1G, ("%u\n", cbModule), VERR_OUT_OF_RANGE); /* * Forward the request to GMM (ring-0). */ PGMMUNREGISTERSHAREDMODULEREQ pReq = (PGMMUNREGISTERSHAREDMODULEREQ)RTMemAlloc(sizeof(*pReq)); AssertReturn(pReq, VERR_NO_MEMORY); pReq->GCBaseAddr = GCBaseAddr; pReq->u32Alignment = 0; pReq->cbModule = cbModule; int rc = RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName); if (RT_SUCCESS(rc)) { rc = RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion); if (RT_SUCCESS(rc)) { pgmR3PhysAssertSharedPageChecksums(pVM); rc = GMMR3UnregisterSharedModule(pVM, pReq); pgmR3PhysAssertSharedPageChecksums(pVM); # ifdef VBOX_STRICT /* * Update our local tracking. */ for (unsigned i = 0; i < g_cSharedModules; i++) { if ( g_apSharedModules[i] && !strcmp(g_apSharedModules[i]->szName, pszModuleName) && !strcmp(g_apSharedModules[i]->szVersion, pszVersion)) { RTMemFree(g_apSharedModules[i]); g_apSharedModules[i] = NULL; g_cSharedModules--; break; } } # endif /* VBOX_STRICT */ } } RTMemFree(pReq); return rc; }
/** * Unregisters a shared module for the VM * * @returns IPRT status code. * @param pszModuleName Module name * @param pszVersion Module version * @param GCBaseAddr Module base address * @param cbModule Module size */ VBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule) { VMMDevSharedModuleUnregistrationRequest Req; vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule); Req.GCBaseAddr = GCBaseAddr; Req.cbModule = cbModule; if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS) { return VERR_BUFFER_OVERFLOW; } return vbglR3GRPerform(&Req.header); }
VBGLR3DECL(int) VbglR3DnDConnect(uint32_t *pu32ClientId) { /* Validate input */ AssertPtrReturn(pu32ClientId, VERR_INVALID_POINTER); /* Initialize header */ VBoxGuestHGCMConnectInfo Info; RT_ZERO(Info.Loc.u); Info.result = VERR_WRONG_ORDER; Info.u32ClientID = UINT32_MAX; /* try make valgrind shut up. */ /* Initialize parameter */ Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing; int rc = RTStrCopy(Info.Loc.u.host.achName, sizeof(Info.Loc.u.host.achName), "VBoxDragAndDropSvc"); if (RT_FAILURE(rc)) return rc; /* Do request */ rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info)); if (RT_SUCCESS(rc)) { rc = Info.result; if (RT_SUCCESS(rc)) *pu32ClientId = Info.u32ClientID; } if (rc == VERR_HGCM_SERVICE_NOT_FOUND) rc = VINF_PERMISSION_DENIED; return rc; }
/** * Adds a directory. * * @returns IPRT status code (fully bitched). * @param pszPath The directory path. * @param pCfg The configuration. */ static int rtDbgSymCacheAddDir(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg) { /* * Set up the path buffer, stripping any filter. */ char szPath[RTPATH_MAX]; int rc = RTStrCopy(szPath, sizeof(szPath) - 2, pszPath); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Path too long: '%s'", pszPath); size_t cchPath = strlen(pszPath); if (!cchPath) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Path empty: '%s'", pszPath); if (pCfg->pszFilter) szPath[cchPath - strlen(pCfg->pszFilter)] = '\0'; cchPath = RTPathStripTrailingSlash(szPath); if (!RTPATH_IS_SEP(pszPath[cchPath - 1])) { szPath[cchPath++] = RTPATH_SLASH; szPath[cchPath] = '\0'; } /* * Let the worker do the rest. */ RTDIRENTRYEX DirEntry; return rtDbgSymCacheAddDirWorker(szPath, cchPath, &DirEntry, pCfg); }
int DumpHtml(char* src, size_t cb) { size_t lenght = 0; int rc = RTStrNLenEx(src, cb, &lenght); if (RT_SUCCESS(rc)) { char* buf = (char*)RTMemAlloc(cb + 1); if (buf != NULL) { RT_BZERO(buf, cb + 1); rc = RTStrCopy(buf, cb, (const char*)src); if (RT_SUCCESS(rc)) { for (int i = 0; i < cb; ++i) { if (buf[i] == '\n' || buf[i] == '\r') buf[i] = ' '; } } else { Log(("Error in copying string.\n")); } Log(("Removed \\r\\n: %s\n", buf)); RTMemFree(buf); } else { rc = VERR_NO_MEMORY; Log(("Not enough memory to allocate buffer.\n")); } } return rc; }
RTDECL(int) RTLocaleQueryLocaleName(char *pszName, size_t cbName) { const char *pszLocale = setlocale(LC_ALL, NULL); if (!pszLocale) return RTStrCopy(pszName, cbName, pszLocale); return VERR_NOT_AVAILABLE; }
/** * Verifies the manifest and its signature. * * @returns VBox status code, failures with message. * @param hManifestFile The xml from the extension pack. * @param pszExtPackName The expected extension pack name. This can be * NULL, in which we don't have any expectations. * @param pszError Where to store an error message on failure. * @param cbError The size of the buffer @a pszError points to. */ static int vboxExtPackVerifyXml(RTVFSFILE hXmlFile, const char *pszExtPackName, char *pszError, size_t cbError) { /* * Load the XML. */ VBOXEXTPACKDESC ExtPackDesc; RTCString *pstrErr = VBoxExtPackLoadDescFromVfsFile(hXmlFile, &ExtPackDesc, NULL); if (pstrErr) { RTStrCopy(pszError, cbError, pstrErr->c_str()); delete pstrErr; return VERR_PARSE_ERROR; } /* * Check the name. */ /** @todo drop this restriction after the old install interface is * dropped. */ int rc = VINF_SUCCESS; if ( pszExtPackName && !ExtPackDesc.strName.equalsIgnoreCase(pszExtPackName)) rc = vboxExtPackReturnError(VERR_NOT_EQUAL, pszError, cbError, "The name of the downloaded file and the name stored inside the extension pack does not match" " (xml='%s' file='%s')", ExtPackDesc.strName.c_str(), pszExtPackName); return rc; }
DECLVBGL(int) vboxCrCtlConConnect(HVBOXCRCTL hCtl, uint32_t *pu32ClientID) { VBoxGuestHGCMConnectInfo info; int rc; if (!hCtl || !pu32ClientID) return VERR_INVALID_PARAMETER; memset(&info, 0, sizeof (info)); info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing; RTStrCopy(info.Loc.u.host.achName, sizeof (info.Loc.u.host.achName), "VBoxSharedCrOpenGL"); rc = vbglDriverIOCtl (&hCtl->driver, VBOXGUEST_IOCTL_HGCM_CONNECT, &info, sizeof (info)); if (RT_SUCCESS(rc)) { rc = info.result; if (RT_SUCCESS(rc)) { Assert(info.u32ClientID); *pu32ClientID = info.u32ClientID; return rc; } } Assert(RT_FAILURE(rc)); *pu32ClientID = 0; return rc; }
DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath) { /* * Read the /proc/self/exe link, convert to native and return it. */ int cchLink = readlink("/proc/self/exe", pszPath, cchPath - 1); if (cchLink > 0 && (size_t)cchLink <= cchPath - 1) { pszPath[cchLink] = '\0'; char const *pszTmp; int rc = rtPathFromNative(&pszTmp, pszPath, NULL); AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, cchLink, pszPath), rc); if (pszTmp != pszPath) { rc = RTStrCopy(pszPath, cchPath, pszTmp); rtPathFreeIprt(pszTmp, pszPath); } return rc; } int err = errno; int rc = RTErrConvertFromErrno(err); AssertMsgFailed(("rc=%Rrc err=%d cchLink=%d\n", rc, err, cchLink)); return rc; }
/** * Opens the output file. * * @returns Command exit, error messages written using RTMsg*. * * @param pszFile The input filename. * @param pOpts The options, szOutput will be filled in by this * function on success. * @param phVfsIos Where to return the output stream handle. * * @remarks This is actually not quite the way we need to do things. * * First of all, we need a GZIP file system stream for a real GZIP * implementation, since there may be more than one file in the gzipped * file. * * Second, we need to open the output files as we encounter files in the input * file system stream. The gzip format contains timestamp and usually a * filename, the default is to use this name (see the --no-name * option). */ static RTEXITCODE gzipOpenOutput(const char *pszFile, PRTGZIPCMDOPTS pOpts, PRTVFSIOSTREAM phVfsIos) { int rc; if (!strcmp(pszFile, "-") || pOpts->fStdOut) { strcpy(pOpts->szOutput, "-"); if ( !pOpts->fForce && !pOpts->fDecompress && gzipIsStdHandleATty(RTHANDLESTD_OUTPUT)) return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Yeah, right. I'm not writing any compressed data to the terminal without --force.\n"); rc = RTVfsIoStrmFromStdHandle(RTHANDLESTD_OUTPUT, RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, true /*fLeaveOpen*/, phVfsIos); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening standard output: %Rrc", rc); } else { Assert(!RTVfsChainIsSpec(pszFile)); /* Construct an output filename. */ rc = RTStrCopy(pOpts->szOutput, sizeof(pOpts->szOutput), pszFile); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error constructing output filename: %Rrc", rc); if (pOpts->fDecompress) { /** @todo take filename from archive? */ size_t cchSuff = strlen(pOpts->pszSuff); Assert(cchSuff > 0); size_t cch = strlen(pOpts->szOutput); if ( cch <= cchSuff || strcmp(&pOpts->szOutput[cch - cchSuff], pOpts->pszSuff)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Input file does not end with: '%s'", pOpts->pszSuff); pOpts->szOutput[cch - cchSuff] = '\0'; if (!RTPathFilename(pOpts->szOutput)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error constructing output filename: Input file name is all suffix."); } else { rc = RTStrCat(pOpts->szOutput, sizeof(pOpts->szOutput), pOpts->pszSuff); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error constructing output filename: %Rrc", rc); } /* Open the output file. */ uint32_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE; if (pOpts->fForce) fOpen |= RTFILE_O_CREATE_REPLACE; else fOpen |= RTFILE_O_CREATE; rc = RTVfsIoStrmOpenNormal(pOpts->szOutput, fOpen, phVfsIos); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening output file '%s': %Rrc", pOpts->szOutput, rc); } return RTEXITCODE_SUCCESS; }
DECLVBGL(int) VbglR0CrCtlConConnect(VBGLCRCTLHANDLE hCtl, HGCMCLIENTID *pidClient) { VBoxGuestHGCMConnectInfo info; int rc; if (!hCtl || !pidClient) return VERR_INVALID_PARAMETER; RT_ZERO(info); info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing; RTStrCopy(info.Loc.u.host.achName, sizeof(info.Loc.u.host.achName), "VBoxSharedCrOpenGL"); rc = vbglDriverIOCtl(&hCtl->driver, VBOXGUEST_IOCTL_HGCM_CONNECT, &info, sizeof(info)); if (RT_SUCCESS(rc)) { rc = info.result; if (RT_SUCCESS(rc)) { Assert(info.u32ClientID); *pidClient = info.u32ClientID; return rc; } } AssertRC(rc); *pidClient = 0; return rc; }
RTDECL(int) RTPathAppPrivateArch(char *pszPath, size_t cchPath) { #if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH) return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH); #else return RTPathExecDir(pszPath, cchPath); #endif }
static void testCopy1(RTTEST hTest) { RTTestISub("RTStrCopy"); char *pszBuf4H = (char *)RTTestGuardedAllocHead(hTest, 4); char *pszBuf4T = (char *)RTTestGuardedAllocTail(hTest, 4); RTTESTI_CHECK_RC(RTStrCopy(pszBuf4H, 4, "abc"), VINF_SUCCESS); RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0); RTTESTI_CHECK_RC(RTStrCopy(pszBuf4T, 4, "abc"), VINF_SUCCESS); RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0); RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4); RTTESTI_CHECK_RC(RTStrCopy(pszBuf4H, 4, "abcd"), VERR_BUFFER_OVERFLOW); RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0); RTTESTI_CHECK_RC(RTStrCopy(pszBuf4T, 4, "abcd"), VERR_BUFFER_OVERFLOW); RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0); }
RTDECL(int) RTPathSharedLibs(char *pszPath, size_t cchPath) { #if !defined(RT_OS_WINDOWS) && defined(RTPATH_SHARED_LIBS) return RTStrCopy(pszPath, cchPath, RTPATH_SHARED_LIBS); #else return RTPathExecDir(pszPath, cchPath); #endif }
int rtPathFromNativeCopy(char *pszPath, size_t cbPath, const char *pszNativePath, const char *pszBasePath) { int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/); if (RT_SUCCESS(rc)) rc = RTStrCopy(pszPath, cbPath, pszNativePath); NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */ return rc; }
/** * @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo} */ static DECLCALLBACK(int) rtZipTarFssBaseObj_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr) { PRTZIPTARBASEOBJ pThis = (PRTZIPTARBASEOBJ)pvThis; /* * Copy the desired data. */ switch (enmAddAttr) { case RTFSOBJATTRADD_NOTHING: case RTFSOBJATTRADD_UNIX: *pObjInfo = pThis->ObjInfo; break; case RTFSOBJATTRADD_UNIX_OWNER: *pObjInfo = pThis->ObjInfo; pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX_OWNER; pObjInfo->Attr.u.UnixOwner.uid = pThis->ObjInfo.Attr.u.Unix.uid; pObjInfo->Attr.u.UnixOwner.szName[0] = '\0'; if (rtZipTarReaderHasUserName(pThis->pTarReader)) RTStrCopy(pObjInfo->Attr.u.UnixOwner.szName, sizeof(pObjInfo->Attr.u.UnixOwner.szName), pThis->pTarReader->Hdr.Common.uname); break; case RTFSOBJATTRADD_UNIX_GROUP: *pObjInfo = pThis->ObjInfo; pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX_GROUP; pObjInfo->Attr.u.UnixGroup.gid = pThis->ObjInfo.Attr.u.Unix.gid; pObjInfo->Attr.u.UnixGroup.szName[0] = '\0'; if (rtZipTarReaderHasGroupName(pThis->pTarReader)) RTStrCopy(pObjInfo->Attr.u.UnixGroup.szName, sizeof(pObjInfo->Attr.u.UnixGroup.szName), pThis->pTarReader->Hdr.Common.gname); break; case RTFSOBJATTRADD_EASIZE: *pObjInfo = pThis->ObjInfo; pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_EASIZE; RT_ZERO(pObjInfo->Attr.u); break; default: return VERR_NOT_SUPPORTED; } return VINF_SUCCESS; }
/** * Registers a new shared module for the VM * * @returns IPRT status code. * @param pszModuleName Module name * @param pszVersion Module version * @param GCBaseAddr Module base address * @param cbModule Module size * @param cRegions Number of shared region descriptors * @param pRegions Shared region(s) */ VBGLR3DECL(int) VbglR3RegisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule, unsigned cRegions, VMMDEVSHAREDREGIONDESC *pRegions) { VMMDevSharedModuleRegistrationRequest *pReq; int rc; /* Sanity check. */ AssertReturn(cRegions < VMMDEVSHAREDREGIONDESC_MAX, VERR_INVALID_PARAMETER); pReq = (VMMDevSharedModuleRegistrationRequest *)RTMemAllocZ(RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions])); AssertReturn(pReq, VERR_NO_MEMORY); vmmdevInitRequest(&pReq->header, VMMDevReq_RegisterSharedModule); pReq->header.size = RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]); pReq->GCBaseAddr = GCBaseAddr; pReq->cbModule = cbModule; pReq->cRegions = cRegions; #ifdef RT_OS_WINDOWS # if ARCH_BITS == 32 pReq->enmGuestOS = VBOXOSFAMILY_Windows32; # else pReq->enmGuestOS = VBOXOSFAMILY_Windows64; # endif #else /** todo */ pReq->enmGuestOS = VBOXOSFAMILY_Unknown; #endif for (unsigned i = 0; i < cRegions; i++) pReq->aRegions[i] = pRegions[i]; if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS) { rc = VERR_BUFFER_OVERFLOW; goto end; } rc = vbglR3GRPerform(&pReq->header); end: RTMemFree(pReq); return rc; }
void XmlFileWriter::write(const char *pcszFilename, bool fSafe) { if (!fSafe) writeInternal(pcszFilename, fSafe); else { /* Empty string and directory spec must be avoid. */ if (RTPathFilename(pcszFilename) == NULL) throw xml::LogicError(RT_SRC_POS); /* Construct both filenames first to ease error handling. */ char szTmpFilename[RTPATH_MAX]; int rc = RTStrCopy(szTmpFilename, sizeof(szTmpFilename) - strlen(s_pszTmpSuff), pcszFilename); if (RT_FAILURE(rc)) throw EIPRTFailure(rc, "RTStrCopy"); strcat(szTmpFilename, s_pszTmpSuff); char szPrevFilename[RTPATH_MAX]; rc = RTStrCopy(szPrevFilename, sizeof(szPrevFilename) - strlen(s_pszPrevSuff), pcszFilename); if (RT_FAILURE(rc)) throw EIPRTFailure(rc, "RTStrCopy"); strcat(szPrevFilename, s_pszPrevSuff); /* Write the XML document to the temporary file. */ writeInternal(szTmpFilename, fSafe); /* Make a backup of any existing file (ignore failure). */ uint64_t cbPrevFile; rc = RTFileQuerySize(pcszFilename, &cbPrevFile); if (RT_SUCCESS(rc) && cbPrevFile >= 16) RTFileRename(pcszFilename, szPrevFilename, RTPATHRENAME_FLAGS_REPLACE); /* Commit the temporary file. Just leave the tmp file behind on failure. */ rc = RTFileRename(szTmpFilename, pcszFilename, RTPATHRENAME_FLAGS_REPLACE); if (RT_FAILURE(rc)) throw EIPRTFailure(rc, "Failed to replace '%s' with '%s'", pcszFilename, szTmpFilename); /* Flush the directory changes (required on linux at least). */ RTPathStripFilename(szTmpFilename); rc = RTDirFlush(szTmpFilename); AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc)); } }
RTDECL(int) RTPathAppPrivateNoArch(char *pszPath, size_t cchPath) { #if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE) return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE); #elif defined(RT_OS_SOLARIS) return rtPathSolarisArchHack(pszPath, cchPath); #else return RTPathExecDir(pszPath, cchPath); #endif }
RTDECL(int) RTPathUserDocuments(char *pszPath, size_t cchPath) { /* * Validate input */ AssertPtrReturn(pszPath, VERR_INVALID_POINTER); AssertReturn(cchPath, VERR_INVALID_PARAMETER); /* * Try NSSystemDirectories first since that works for directories that doesn't exist. */ int rc = VERR_PATH_NOT_FOUND; NSSearchPathEnumerationState EnmState = NSStartSearchPathEnumeration(NSDocumentDirectory, NSUserDomainMask); if (EnmState != 0) { char szTmp[PATH_MAX]; szTmp[0] = szTmp[PATH_MAX - 1] = '\0'; EnmState = NSGetNextSearchPathEnumeration(EnmState, szTmp); if (EnmState != 0) { size_t cchTmp = strlen(szTmp); if (cchTmp >= cchPath) return VERR_BUFFER_OVERFLOW; if (szTmp[0] == '~' && szTmp[1] == '/') { /* Expand tilde. */ rc = RTPathUserHome(pszPath, cchPath - cchTmp + 2); if (RT_FAILURE(rc)) return rc; rc = RTPathAppend(pszPath, cchPath, &szTmp[2]); } else rc = RTStrCopy(pszPath, cchPath, szTmp); return rc; } } #ifdef IPRT_USE_CORE_SERVICE_FOR_USER_DOCUMENTS /* * Fall back on FSFindFolder in case the above should fail... */ FSRef ref; OSErr err = FSFindFolder(kOnAppropriateDisk, kDocumentsFolderType, false /* createFolder */, &ref); if (err == noErr) { err = FSRefMakePath(&ref, (UInt8*)pszPath, cchPath); if (err == noErr) return VINF_SUCCESS; } #endif Assert(RT_FAILURE_NP(rc)); return rc; }
RTDECL(int) RTDirFlushParent(const char *pszChild) { char szPath[RTPATH_MAX]; int rc = RTStrCopy(szPath, sizeof(szPath), pszChild); if (RT_SUCCESS(rc)) { RTPathStripFilename(szPath); rc = RTDirFlush(szPath); } return rc; }
static int netPfStrPortParse(char *pszRaw, int cbRaw, uint16_t *pu16Port) { char *pszEndOfPort = NULL; uint16_t u16Port = 0; int idxRaw = 1; /* we increment pszRaw after checks. */ int cbRest = 0; size_t cbPort = 0; AssertPtrReturn(pszRaw, -1); AssertPtrReturn(pu16Port, -1); AssertReturn(pszRaw[0] == PF_FIELD_SEPARATOR, -1); pszRaw++; /* skip line separator */ cbRaw --; pszEndOfPort = RTStrStr(pszRaw, ":"); if (!pszEndOfPort) { cbRest = strlen(pszRaw); Assert(cbRaw == cbRest); /* XXX: Assumption that if string is too big, it will be reported by * RTStrToUint16. */ if (cbRest > 0) { pszEndOfPort = pszRaw + cbRest; cbPort = cbRest; } else return -1; } else cbPort = pszEndOfPort - pszRaw; idxRaw += cbPort; Assert(cbRest || pszRaw[idxRaw - 1] == PF_FIELD_SEPARATOR); /* we are 1 char ahead */ char szPort[10]; RT_ZERO(szPort); Assert(idxRaw > 0); RTStrCopy(szPort, RT_MIN(sizeof(szPort), (size_t)(cbPort) + 1), pszRaw); if (!(u16Port = RTStrToUInt16(szPort))) return -1; *pu16Port = u16Port; return idxRaw; }
/** * @interface_method_impl(PDMINVRAM,pfnStoreNvramValue) */ DECLCALLBACK(int) drvNvram_pfnLoadNvramValue(PPDMINVRAM pInterface, int idxVariable, RTUUID *pVendorUuid, char *pcszVariableName, size_t *pcbVariableName, uint8_t *pu8Value, size_t *pcbValue) { int rc = VINF_SUCCESS; char szExtraDataKey[256]; Bstr bstrValue; HRESULT hrc; LogFlowFunc(("ENTER: idxVariable:%d, *pcbVariableName:%d, *pcbValue:%d\n", idxVariable, *pcbVariableName, *pcbValue)); PNVRAM pThis = RT_FROM_MEMBER(pInterface, NVRAM, INvram); if (!pThis->fPermanentSave) { rc = VERR_NOT_FOUND; LogFlowFuncLeaveRC(rc); return rc; } RT_ZERO(szExtraDataKey); RTStrPrintf(szExtraDataKey, 256, "VBoxInternal/Devices/efi/0/LUN#0/Config/NVRAM/%d/VariableName", idxVariable); hrc = pThis->pNvram->getParent()->machine()->GetExtraData(Bstr(szExtraDataKey).raw(), bstrValue.asOutParam()); if (!SUCCEEDED(hrc)) return VERR_NOT_FOUND; *pcbVariableName = RTStrCopy(pcszVariableName, 1024, Utf8Str(bstrValue).c_str()); RT_ZERO(szExtraDataKey); RTStrPrintf(szExtraDataKey, 256, "VBoxInternal/Devices/efi/0/LUN#0/Config/NVRAM/%d/VendorGuid", idxVariable); hrc = pThis->pNvram->getParent()->machine()->GetExtraData(Bstr(szExtraDataKey).raw(), bstrValue.asOutParam()); RTUuidFromStr(pVendorUuid, Utf8Str(bstrValue).c_str()); #if 0 RT_ZERO(szExtraDataKey); RTStrPrintf(szExtraDataKey, 256, "VBoxInternal/Devices/efi/0/LUN#0/Config/NVRAM/%d/VariableValueLength", idxVariable); hrc = pThis->pNvram->getParent()->machine()->GetExtraData(Bstr(szExtraDataKey).raw(), bstrValue.asOutParam()); *pcbValue = Utf8Str(bstrValue).toUInt32(); #endif RT_ZERO(szExtraDataKey); RTStrPrintf(szExtraDataKey, 256, "VBoxInternal/Devices/efi/0/LUN#0/Config/NVRAM/%d/VariableValue", idxVariable); hrc = pThis->pNvram->getParent()->machine()->GetExtraData(Bstr(szExtraDataKey).raw(), bstrValue.asOutParam()); rc = RTBase64Decode(Utf8Str(bstrValue).c_str(), pu8Value, 1024, pcbValue, NULL); AssertRCReturn(rc, rc); pThis->cLoadedVariables++; LogFlowFuncLeaveRC(rc); return rc; }
RTDECL(int) RTSymlinkRead(const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead) { char *pszMyTarget; int rc = RTSymlinkReadA(pszSymlink, &pszMyTarget); if (RT_SUCCESS(rc)) { rc = RTStrCopy(pszTarget, cbTarget, pszMyTarget); RTStrFree(pszMyTarget); } LogFlow(("RTSymlinkRead(%p={%s}): returns %Rrc\n", pszSymlink, pszSymlink, rc)); return rc; }
/** * Set user-owner additional attributes. * * @param pObjInfo The object info to fill add attrs for. * @param uid The user id. */ void rtFsObjInfoAttrSetUnixOwner(PRTFSOBJINFO pObjInfo, RTUID uid) { pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX_OWNER; pObjInfo->Attr.u.UnixOwner.uid = uid; pObjInfo->Attr.u.UnixOwner.szName[0] = '\0'; char achBuf[_4K]; struct passwd Pwd; struct passwd *pPwd; int rc = getpwuid_r(uid, &Pwd, achBuf, sizeof(achBuf), &pPwd); if (!rc && pPwd) RTStrCopy(pObjInfo->Attr.u.UnixOwner.szName, sizeof(pObjInfo->Attr.u.UnixOwner.szName), pPwd->pw_name); }
RTDECL(int) RTErrInfoSet(PRTERRINFO pErrInfo, int rc, const char *pszMsg) { if (pErrInfo) { AssertPtr(pErrInfo); Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC); RTStrCopy(pErrInfo->pszMsg, pErrInfo->cbMsg, pszMsg); pErrInfo->rc = rc; pErrInfo->fFlags |= RTERRINFO_FLAGS_SET; } return rc; }