003 File Manager
Current Path:
/usr/src/contrib/processor-trace/libipt/test/src
usr
/
src
/
contrib
/
processor-trace
/
libipt
/
test
/
src
/
📁
..
📄
ptunit-asid.c
(9.16 KB)
📄
ptunit-block_cache.c
(8.52 KB)
📄
ptunit-block_decoder.c
(7.93 KB)
📄
ptunit-config.c
(14.32 KB)
📄
ptunit-cpp.cpp
(2.45 KB)
📄
ptunit-cpu.c
(4.41 KB)
📄
ptunit-encoder.c
(5.57 KB)
📄
ptunit-event_queue.c
(11.3 KB)
📄
ptunit-fetch.c
(14.43 KB)
📄
ptunit-ild.c
(15.98 KB)
📄
ptunit-image.c
(54.98 KB)
📄
ptunit-image_section_cache.c
(44.58 KB)
📄
ptunit-insn_decoder.c
(7.95 KB)
📄
ptunit-last_ip.c
(8.58 KB)
📄
ptunit-mapped_section.c
(4.81 KB)
📄
ptunit-msec_cache.c
(9.19 KB)
📄
ptunit-packet.c
(20.4 KB)
📄
ptunit-packet_decoder.c
(6.42 KB)
📄
ptunit-query.c
(83.63 KB)
📄
ptunit-retstack.c
(5.17 KB)
📄
ptunit-section-file.c
(4.4 KB)
📄
ptunit-section.c
(33.38 KB)
📄
ptunit-sync.c
(7.6 KB)
📄
ptunit-time.c
(9.74 KB)
📄
ptunit-tnt_cache.c
(5.56 KB)
Editing: ptunit-section-file.c
/* * Copyright (c) 2015-2019, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "pt_section.h" #include "pt_section_file.h" #include "intel-pt.h" #include <stdlib.h> #include <stdio.h> /* This is a variation of ptunit-section.c. * * We provide pt_section_map() et.al. that are normally provided by mmap-based * section implementations. Our implementation falls back to file-based * sections so we're able to test them. * * The actual test is in ptunit-section.c. */ /* The file status used for detecting changes to a file between unmap and map. * * In our case, the changes always affect the size of the file. */ struct pt_file_status { /* The size in bytes. */ long size; }; int pt_section_mk_status(void **pstatus, uint64_t *psize, const char *filename) { struct pt_file_status *status; FILE *file; long size; int errcode; if (!pstatus || !psize) return -pte_internal; file = fopen(filename, "rb"); if (!file) return -pte_bad_image; errcode = fseek(file, 0, SEEK_END); if (errcode) { errcode = -pte_bad_image; goto out_file; } size = ftell(file); if (size < 0) { errcode = -pte_bad_image; goto out_file; } status = malloc(sizeof(*status)); if (!status) { errcode = -pte_nomem; goto out_file; } status->size = size; *pstatus = status; *psize = (uint64_t) size; errcode = 0; out_file: fclose(file); return errcode; } static int pt_section_map_success(struct pt_section *section) { uint16_t mcount; int errcode, status; if (!section) return -pte_internal; mcount = section->mcount + 1; if (!mcount) { (void) pt_section_unlock(section); return -pte_overflow; } section->mcount = mcount; errcode = pt_section_unlock(section); if (errcode < 0) return errcode; status = pt_section_on_map(section); if (status < 0) { (void) pt_section_unmap(section); return status; } return 0; } int pt_section_map(struct pt_section *section) { struct pt_file_status *status; const char *filename; uint16_t mcount; FILE *file; long size; int errcode; if (!section) return -pte_internal; errcode = pt_section_lock(section); if (errcode < 0) return errcode; mcount = section->mcount; if (mcount) return pt_section_map_success(section); if (section->mapping) goto out_unlock; filename = section->filename; if (!filename) goto out_unlock; status = section->status; if (!status) goto out_unlock; errcode = -pte_bad_image; file = fopen(filename, "rb"); if (!file) goto out_unlock; errcode = fseek(file, 0, SEEK_END); if (errcode) { errcode = -pte_bad_image; goto out_file; } errcode = -pte_bad_image; size = ftell(file); if (size < 0) goto out_file; if (size != status->size) goto out_file; /* We need to keep the file open on success. It will be closed when * the section is unmapped. */ errcode = pt_sec_file_map(section, file); if (!errcode) return pt_section_map_success(section); out_file: fclose(file); out_unlock: (void) pt_section_unlock(section); return errcode; }
Upload File
Create Folder