tools/testing/selftests/net/tcp_mmap.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_mmap.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/tcp_mmap.c- Extension
.c- Size
- 15934 bytes
- Lines
- 613
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
pthread.hsys/types.hfcntl.herror.hsys/socket.hsys/mman.hsys/resource.hunistd.hstring.hstdlib.hstdio.herrno.htime.hsys/time.hnetinet/in.harpa/inet.hpoll.hlinux/tcp.hassert.hopenssl/pem.h
Detected Declarations
function prefetchfunction hash_zonefunction tcp_info_get_rcv_mssfunction apply_rcvsnd_buffunction setup_sockaddrfunction do_acceptfunction default_huge_page_sizefunction randomizefunction main
Annotated Snippet
if (raddr == (void *)-1) {
perror("mmap");
zflg = 0;
} else {
addr = ALIGN_PTR_UP(raddr, map_align);
}
}
if (integrity) {
ctx = EVP_MD_CTX_new();
if (!ctx) {
perror("cannot enable SHA computing");
goto error;
}
EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
}
while (1) {
struct pollfd pfd = { .fd = fd, .events = POLLIN, };
int sub;
poll(&pfd, 1, 10000);
if (zflg) {
socklen_t zc_len = sizeof(zc);
int res;
memset(&zc, 0, sizeof(zc));
zc.address = (__u64)((unsigned long)addr);
zc.length = min(chunk_size, FILE_SZ - total);
res = getsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE,
&zc, &zc_len);
if (res == -1)
break;
if (zc.length) {
assert(zc.length <= chunk_size);
if (integrity)
EVP_DigestUpdate(ctx, addr, zc.length);
total_mmap += zc.length;
if (xflg)
hash_zone(addr, zc.length);
/* It is more efficient to unmap the pages right now,
* instead of doing this in next TCP_ZEROCOPY_RECEIVE.
*/
madvise(addr, zc.length, MADV_DONTNEED);
total += zc.length;
}
if (zc.recv_skip_hint) {
assert(zc.recv_skip_hint <= chunk_size);
lu = read(fd, buffer, min(zc.recv_skip_hint,
FILE_SZ - total));
if (lu > 0) {
if (integrity)
EVP_DigestUpdate(ctx, buffer, lu);
if (xflg)
hash_zone(buffer, lu);
total += lu;
}
if (lu == 0)
goto end;
}
continue;
}
sub = 0;
while (sub < chunk_size) {
lu = read(fd, buffer + sub, min(chunk_size - sub,
FILE_SZ - total));
if (lu == 0)
goto end;
if (lu < 0)
break;
if (integrity)
EVP_DigestUpdate(ctx, buffer + sub, lu);
if (xflg)
hash_zone(buffer + sub, lu);
total += lu;
sub += lu;
}
}
end:
gettimeofday(&t1, NULL);
delta_usec = (t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec;
if (integrity) {
fcntl(fd, F_SETFL, 0);
EVP_DigestFinal_ex(ctx, digest, &digest_len);
lu = read(fd, buffer, SHA256_DIGEST_LENGTH);
if (lu != SHA256_DIGEST_LENGTH)
perror("Error: Cannot read SHA256\n");
if (memcmp(digest, buffer,
Annotation
- Immediate include surface: `pthread.h`, `sys/types.h`, `fcntl.h`, `error.h`, `sys/socket.h`, `sys/mman.h`, `sys/resource.h`, `unistd.h`.
- Detected declarations: `function prefetch`, `function hash_zone`, `function tcp_info_get_rcv_mss`, `function apply_rcvsnd_buf`, `function setup_sockaddr`, `function do_accept`, `function default_huge_page_size`, `function randomize`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.