17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*25cf1a30Sjl139090 * Common Development and Distribution License (the "License"). 6*25cf1a30Sjl139090 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*25cf1a30Sjl139090 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*25cf1a30Sjl139090 * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_DR_UTIL_H_ 277c478bd9Sstevel@tonic-gate #define _SYS_DR_UTIL_H_ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/memlist.h> 337c478bd9Sstevel@tonic-gate #include <sys/sbd_ioctl.h> 347c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 357c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef __cplusplus 387c478bd9Sstevel@tonic-gate extern "C" { 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #define GETSTRUCT(t, n) \ 427c478bd9Sstevel@tonic-gate ((t *)kmem_zalloc((size_t)(n) * sizeof (t), KM_SLEEP)) 437c478bd9Sstevel@tonic-gate #define FREESTRUCT(p, t, n) \ 447c478bd9Sstevel@tonic-gate (kmem_free((caddr_t)(p), sizeof (t) * (size_t)(n))) 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define DRERR_SET_C(epps, eppn) \ 477c478bd9Sstevel@tonic-gate if (*(epps) == NULL) \ 487c478bd9Sstevel@tonic-gate *(epps) = *(eppn); \ 497c478bd9Sstevel@tonic-gate else \ 507c478bd9Sstevel@tonic-gate sbd_err_clear(eppn) 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #ifdef DEBUG 537c478bd9Sstevel@tonic-gate #define MEMLIST_DUMP(ml) memlist_dump(ml) 547c478bd9Sstevel@tonic-gate #else 557c478bd9Sstevel@tonic-gate #define MEMLIST_DUMP(ml) 567c478bd9Sstevel@tonic-gate #endif 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate extern sbd_error_t *sbd_err_new(int e_code, char *fmt, va_list args); 597c478bd9Sstevel@tonic-gate extern void sbd_err_log(sbd_error_t *ep, int ce); 607c478bd9Sstevel@tonic-gate extern void sbd_err_clear(sbd_error_t **ep); 617c478bd9Sstevel@tonic-gate extern void sbd_err_set_c(sbd_error_t **ep, int ce, 627c478bd9Sstevel@tonic-gate int e_code, char *fmt, ...); 637c478bd9Sstevel@tonic-gate extern void sbd_err_set(sbd_error_t **ep, int ce, 647c478bd9Sstevel@tonic-gate int e_code, char *fmt, ...); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate extern sbd_error_t *drerr_new(int log, int e_code, char *fmt, ...); 677c478bd9Sstevel@tonic-gate extern sbd_error_t *drerr_new_v(int e_code, char *fmt, va_list args); 687c478bd9Sstevel@tonic-gate extern void drerr_set_c(int log, sbd_error_t **ep, 697c478bd9Sstevel@tonic-gate int e_code, char *fmt, ...); 707c478bd9Sstevel@tonic-gate 71*25cf1a30Sjl139090 extern void dr_memlist_delete(struct memlist *mlist); 727c478bd9Sstevel@tonic-gate extern void memlist_dump(struct memlist *mlist); 73*25cf1a30Sjl139090 extern int dr_memlist_intersect(struct memlist *al, 747c478bd9Sstevel@tonic-gate struct memlist *bl); 75*25cf1a30Sjl139090 extern void dr_memlist_coalesce(struct memlist *mlist); 76*25cf1a30Sjl139090 extern struct memlist *dr_memlist_dup(struct memlist *mlist); 77*25cf1a30Sjl139090 extern struct memlist *dr_memlist_add_span(struct memlist *mlist, 78*25cf1a30Sjl139090 uint64_t base, uint64_t len); 79*25cf1a30Sjl139090 extern struct memlist *dr_memlist_del_span(struct memlist *mlist, 80*25cf1a30Sjl139090 uint64_t base, uint64_t len); 81*25cf1a30Sjl139090 extern struct memlist *dr_memlist_cat_span(struct memlist *mlist, 82*25cf1a30Sjl139090 uint64_t base, uint64_t len); 83*25cf1a30Sjl139090 84*25cf1a30Sjl139090 /* 85*25cf1a30Sjl139090 * These are all utilities internal for DR. There are 86*25cf1a30Sjl139090 * similar functions in common/os which have similar names. 87*25cf1a30Sjl139090 * We rename them to make sure there is no name space 88*25cf1a30Sjl139090 * conflict. 89*25cf1a30Sjl139090 */ 90*25cf1a30Sjl139090 #define memlist_delete dr_memlist_delete 91*25cf1a30Sjl139090 #define memlist_intersect dr_memlist_intersect 92*25cf1a30Sjl139090 #define memlist_coalesce dr_memlist_coalesce 93*25cf1a30Sjl139090 #define memlist_dup dr_memlist_dup 94*25cf1a30Sjl139090 #define memlist_add_span dr_memlist_add_span 95*25cf1a30Sjl139090 #define memlist_del_span dr_memlist_del_span 96*25cf1a30Sjl139090 #define memlist_cat_span dr_memlist_cat_span 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #ifdef __cplusplus 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate #endif 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #endif /* _SYS_DR_UTIL_H_ */ 103