xref: /xnu-12377.81.4/osfmk/kdp/output_stages/out_net.c (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #ifdef CONFIG_KDP_INTERACTIVE_DEBUGGING
30 
31 #include <mach/mach_types.h>
32 #include <IOKit/IOTypes.h>
33 #include <kdp/output_stages/output_stages.h>
34 #include <kdp/kdp_core.h>
35 #include <kdp/processor_core.h>
36 
37 static kern_return_t
net_stage_reset(struct kdp_output_stage * stage,__unused const char * corename,__unused kern_coredump_type_t coretype)38 net_stage_reset(struct kdp_output_stage *stage, __unused const char *corename, __unused kern_coredump_type_t coretype)
39 {
40 	stage->kos_bypass = false;
41 	stage->kos_bytes_written = 0;
42 
43 	return KERN_SUCCESS;
44 }
45 
46 static kern_return_t
net_stage_outproc(struct kdp_output_stage * stage,unsigned int request,char * corename,uint64_t length,void * data)47 net_stage_outproc(struct kdp_output_stage *stage, unsigned int request,
48     char *corename, uint64_t length, void * data)
49 {
50 	kern_return_t err = KERN_SUCCESS;
51 
52 	assert(STAILQ_NEXT(stage, kos_next) == NULL);
53 
54 	err = kdp_send_crashdump_data(request, corename, length, data);
55 	if (KERN_SUCCESS != err) {
56 		kern_coredump_log(NULL, "kdp_send_crashdump_data returned 0x%x\n", err);
57 		return err;
58 	}
59 
60 	if (KDP_DATA == request) {
61 		stage->kos_bytes_written += length;
62 	}
63 
64 	return err;
65 }
66 
67 static void
net_stage_free(struct kdp_output_stage * stage)68 net_stage_free(struct kdp_output_stage *stage)
69 {
70 	stage->kos_initialized = false;
71 }
72 
73 kern_return_t
net_stage_initialize(struct kdp_output_stage * stage)74 net_stage_initialize(struct kdp_output_stage *stage)
75 {
76 	assert(stage != NULL);
77 	assert(stage->kos_initialized == false);
78 
79 	stage->kos_funcs.kosf_reset = net_stage_reset;
80 	stage->kos_funcs.kosf_outproc = net_stage_outproc;
81 	stage->kos_funcs.kosf_free = net_stage_free;
82 
83 	stage->kos_initialized = true;
84 
85 	return KERN_SUCCESS;
86 }
87 
88 #endif /* CONFIG_KDP_INTERACTIVE_DEBUGGING */
89