MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sys_kldsym

Function sys_kldsym

freebsd/kern/kern_linker.c:1359–1413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1357}
1358
1359int
1360sys_kldsym(struct thread *td, struct kldsym_args *uap)
1361{
1362 char *symstr = NULL;
1363 c_linker_sym_t sym;
1364 linker_symval_t symval;
1365 linker_file_t lf;
1366 struct kld_sym_lookup lookup;
1367 int error = 0;
1368
1369#ifdef MAC
1370 error = mac_kld_check_stat(td->td_ucred);
1371 if (error)
1372 return (error);
1373#endif
1374
1375 if ((error = copyin(uap->data, &lookup, sizeof(lookup))) != 0)
1376 return (error);
1377 if (lookup.version != sizeof(lookup) ||
1378 uap->cmd != KLDSYM_LOOKUP)
1379 return (EINVAL);
1380 symstr = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
1381 if ((error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL)) != 0)
1382 goto out;
1383 sx_xlock(&kld_sx);
1384 if (uap->fileid != 0) {
1385 lf = linker_find_file_by_id(uap->fileid);
1386 if (lf == NULL)
1387 error = ENOENT;
1388 else if (LINKER_LOOKUP_SYMBOL(lf, symstr, &sym) == 0 &&
1389 LINKER_SYMBOL_VALUES(lf, sym, &symval) == 0) {
1390 lookup.symvalue = (uintptr_t) symval.value;
1391 lookup.symsize = symval.size;
1392 error = copyout(&lookup, uap->data, sizeof(lookup));
1393 } else
1394 error = ENOENT;
1395 } else {
1396 TAILQ_FOREACH(lf, &linker_files, link) {
1397 if (LINKER_LOOKUP_SYMBOL(lf, symstr, &sym) == 0 &&
1398 LINKER_SYMBOL_VALUES(lf, sym, &symval) == 0) {
1399 lookup.symvalue = (uintptr_t)symval.value;
1400 lookup.symsize = symval.size;
1401 error = copyout(&lookup, uap->data,
1402 sizeof(lookup));
1403 break;
1404 }
1405 }
1406 if (lf == NULL)
1407 error = ENOENT;
1408 }
1409 sx_xunlock(&kld_sx);
1410out:
1411 free(symstr, M_TEMP);
1412 return (error);
1413}
1414
1415/*
1416 * Preloaded module support

Callers

nothing calls this directly

Calls 7

mac_kld_check_statFunction · 0.85
mallocFunction · 0.85
linker_find_file_by_idFunction · 0.85
freeFunction · 0.70
copyinFunction · 0.50
copyinstrFunction · 0.50
copyoutFunction · 0.50

Tested by

no test coverage detected