xref: /xnu-8792.81.2/osfmk/kdp/output_stages/out_net.c (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
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 void
net_stage_reset(struct kdp_output_stage * stage)38 net_stage_reset(struct kdp_output_stage *stage)
39 {
40 	stage->kos_bypass = false;
41 	stage->kos_bytes_written = 0;
42 }
43 
44 static kern_return_t
net_stage_outproc(struct kdp_output_stage * stage,unsigned int request,char * corename,uint64_t length,void * data)45 net_stage_outproc(struct kdp_output_stage *stage, unsigned int request,
46     char *corename, uint64_t length, void * data)
47 {
48 	kern_return_t err = KERN_SUCCESS;
49 
50 	assert(STAILQ_NEXT(stage, kos_next) == NULL);
51 
52 	err = kdp_send_crashdump_data(request, corename, length, data);
53 	if (KERN_SUCCESS != err) {
54 		kern_coredump_log(NULL, "kdp_send_crashdump_data returned 0x%x\n", err);
55 		return err;
56 	}
57 
58 	if (KDP_DATA == request) {
59 		stage->kos_bytes_written += length;
60 	}
61 
62 	return err;
63 }
64 
65 static void
net_stage_free(struct kdp_output_stage * stage)66 net_stage_free(struct kdp_output_stage *stage)
67 {
68 	stage->kos_initialized = false;
69 }
70 
71 kern_return_t
net_stage_initialize(struct kdp_output_stage * stage)72 net_stage_initialize(struct kdp_output_stage *stage)
73 {
74 	assert(stage != NULL);
75 	assert(stage->kos_initialized == false);
76 
77 	stage->kos_funcs.kosf_reset = net_stage_reset;
78 	stage->kos_funcs.kosf_outproc = net_stage_outproc;
79 	stage->kos_funcs.kosf_free = net_stage_free;
80 
81 	stage->kos_initialized = true;
82 
83 	return KERN_SUCCESS;
84 }
85 
86 #endif /* CONFIG_KDP_INTERACTIVE_DEBUGGING */
87