void* rpal_memory_alloc ( uint32_t size ) { void* ptr = NULL; unsigned char* realPtr = NULL; if( 0 == g_mem_tag ) { g_mem_tag = OSMalloc_Tagalloc( "hcp_hbs_acq", 0 ); } size += sizeof( uint32_t ); realPtr = OSMalloc( size, g_mem_tag ); if( NULL != realPtr ) { *(uint32_t*)realPtr = size; ptr = realPtr + sizeof( uint32_t ); } return ptr; }
// Driver entry point. Initializes globals and registers driver node in /dev. kern_return_t pmem_start(kmod_info_t * ki, void *d) { int error = 0; pmem_log("Loading /dev/%s driver", pmem_pmem_devname); // Memory allocations are tagged to prevent leaks pmem_tag = OSMalloc_Tagalloc(pmem_tagname, OSMT_DEFAULT); // Allocate one page for zero padding of illegal read requests pmem_zero_page = static_cast<uint8_t *>(OSMalloc(PAGE_SIZE, pmem_tag)); if (pmem_zero_page == NULL) { pmem_error("Failed to allocate memory for page buffer"); return pmem_cleanup(KERN_FAILURE); } bzero(pmem_zero_page, PAGE_SIZE); // Access the boot arguments through the platform export, // and parse the systems physical memory configuration. boot_args * ba = reinterpret_cast<boot_args *>(PE_state.bootArgs); pmem_physmem_size = ba->PhysicalMemorySize; pmem_mmap = reinterpret_cast<EfiMemoryRange *>(ba->MemoryMap + pmem_kernel_voffset); pmem_mmap_desc_size = ba->MemoryMapDescriptorSize; pmem_mmap_size = ba->MemoryMapSize; pmem_log("Size of physical memory:%lld", pmem_physmem_size); pmem_log("Size of physical pages:%d (PAGE_SHIFT=%d, PAGE_MASK=%#016x)", PAGE_SIZE, PAGE_SHIFT, PAGE_MASK); pmem_log("Phys. Memory map at:%#016llx (size:%lld desc_size:%d)", pmem_mmap, pmem_mmap_size, pmem_mmap_desc_size); pmem_log("Number of segments in memory map: %d", pmem_mmap_size / pmem_mmap_desc_size); // Install switch table pmem_devmajor = cdevsw_add(-1, &pmem_cdevsw); if (pmem_devmajor == -1) { pmem_error("Failed to create character device"); return pmem_cleanup(KERN_FAILURE); } // Create physical memory device file pmem_log("Adding node /dev/%s", pmem_pmem_devname); pmem_devpmemnode = devfs_make_node(makedev(pmem_devmajor, pmem_dev_pmem_minor), DEVFS_CHAR, UID_ROOT, GID_WHEEL, 0660, pmem_pmem_devname); if (pmem_devpmemnode == NULL) { pmem_error("Failed to create /dev/%s node", pmem_pmem_devname); return pmem_cleanup(KERN_FAILURE); } pmem_log("obtaining kernel dtb pointer"); __asm__ __volatile__("movq %%cr3, %0" :"=r"(pmem_dtb)); // Only bits 51-12 (inclusive) in cr3 are part of the dtb pointer pmem_dtb &= ~PAGE_MASK; pmem_log("kernel dtb: %#016llx", pmem_dtb); pmem_log("initializing pte_mmap module"); pmem_log("pmem driver loaded, physical memory available in /dev/%s", pmem_pmem_devname); return error; }
errno_t utun_register_control(void) { struct kern_ctl_reg kern_ctl; errno_t result = 0; /* Create a tag to allocate memory */ utun_malloc_tag = OSMalloc_Tagalloc(UTUN_CONTROL_NAME, OSMT_DEFAULT); /* Find a unique value for our interface family */ result = mbuf_tag_id_find(UTUN_CONTROL_NAME, &utun_family); if (result != 0) { printf("utun_register_control - mbuf_tag_id_find_internal failed: %d\n", result); return result; } bzero(&kern_ctl, sizeof(kern_ctl)); strlcpy(kern_ctl.ctl_name, UTUN_CONTROL_NAME, sizeof(kern_ctl.ctl_name)); kern_ctl.ctl_name[sizeof(kern_ctl.ctl_name) - 1] = 0; kern_ctl.ctl_flags = CTL_FLAG_PRIVILEGED | CTL_FLAG_REG_EXTENDED; /* Require root */ kern_ctl.ctl_sendsize = 512 * 1024; kern_ctl.ctl_recvsize = 512 * 1024; kern_ctl.ctl_connect = utun_ctl_connect; kern_ctl.ctl_disconnect = utun_ctl_disconnect; kern_ctl.ctl_send = utun_ctl_send; kern_ctl.ctl_setopt = utun_ctl_setopt; kern_ctl.ctl_getopt = utun_ctl_getopt; kern_ctl.ctl_rcvd = utun_ctl_rcvd; utun_ctl_init_crypto(); result = ctl_register(&kern_ctl, &utun_kctlref); if (result != 0) { printf("utun_register_control - ctl_register failed: %d\n", result); return result; } /* Register the protocol plumbers */ if ((result = proto_register_plumber(PF_INET, utun_family, utun_attach_proto, NULL)) != 0) { printf("utun_register_control - proto_register_plumber(PF_INET, %d) failed: %d\n", utun_family, result); ctl_deregister(utun_kctlref); return result; } /* Register the protocol plumbers */ if ((result = proto_register_plumber(PF_INET6, utun_family, utun_attach_proto, NULL)) != 0) { proto_unregister_plumber(PF_INET, utun_family); ctl_deregister(utun_kctlref); printf("utun_register_control - proto_register_plumber(PF_INET6, %d) failed: %d\n", utun_family, result); return result; } return 0; }
void zfs_context_init(void) { uint64_t kern_mem_size; zfs_lock_attr = lck_attr_alloc_init(); zfs_group_attr = lck_grp_attr_alloc_init(); #if 0 lck_attr_setdebug(zfs_lock_attr); #endif zfs_mutex_group = lck_grp_alloc_init("zfs-mutex", zfs_group_attr); zfs_rwlock_group = lck_grp_alloc_init("zfs-rwlock", zfs_group_attr); zfs_spinlock_group = lck_grp_alloc_init("zfs-spinlock", zfs_group_attr); zfs_kmem_alloc_tag = OSMalloc_Tagalloc("ZFS general purpose", OSMT_DEFAULT); max_ncpus = 1; /* kernel memory space is 4 GB max */ kern_mem_size = MIN(max_mem, (uint64_t)0x0FFFFFFFFULL); /* Calculate number of pages of memory on the system */ physmem = kern_mem_size / PAGE_SIZE; /* Constrain our memory use on smaller memory systems */ if (kern_mem_size <= 0x20000000) zfs_footprint.maximum = kern_mem_size / 7; /* 512MB: ~15 % */ else if (kern_mem_size <= 0x30000000) zfs_footprint.maximum = kern_mem_size / 5; /* 768MB: ~20 % */ else if (kern_mem_size <= 0x40000000) zfs_footprint.maximum = kern_mem_size / 3; /* 1GB: ~33 % */ else /* set to 1GB limit maximum*/ zfs_footprint.maximum = MIN((kern_mem_size / 2), 0x40000000); recalc_target_footprint(100); printf("zfs_context_init: footprint.maximum=%lu, footprint.target=%lu\n", zfs_footprint.maximum, zfs_footprint.target); }
// Driver entry point. Initializes globals and registers driver node in /dev. kern_return_t chipsec_start(kmod_info_t * ki, void *d) { int error = 0; pmem_log("Loading /dev/%s driver", chipsec_devname); // Memory allocations are tagged to prevent leaks pmem_tag = OSMalloc_Tagalloc(pmem_tagname, OSMT_DEFAULT); // Allocate one page for zero padding of illegal read requests pmem_zero_page = static_cast<uint8_t *>(OSMalloc(PAGE_SIZE, pmem_tag)); if (pmem_zero_page == NULL) { pmem_error("Failed to allocate memory for page buffer"); return pmem_cleanup(KERN_FAILURE); } bzero(pmem_zero_page, PAGE_SIZE); // Install the character device chipsec_dev_major = cdevsw_add(-1, &pmem_cdevsw); if (chipsec_dev_major == -1) { pmem_error("Failed to create character device"); return pmem_cleanup(KERN_FAILURE); } // Create physical memory device file pmem_log("Adding node /dev/%s", chipsec_devname); pmem_devpmemnode = devfs_make_node(makedev(chipsec_dev_major, chipsec_dev_minor), DEVFS_CHAR, UID_ROOT, GID_WHEEL, 0660, chipsec_devname); if (pmem_devpmemnode == NULL) { pmem_error("Failed to create /dev/%s node", chipsec_devname); return pmem_cleanup(KERN_FAILURE); } pmem_log("pmem driver loaded, physical memory available in /dev/%s", chipsec_devname); return error; }
//start method bool com_objective_see_firewall::start(IOService *provider) { //return var bool result = false; //dbg msg IOLog("LULU: in %s\n", __FUNCTION__); //super if(TRUE != super::start(provider)) { //bail goto bail; } //alloc memory tag allocTag = OSMalloc_Tagalloc(BUNDLE_ID, OSMT_DEFAULT); if(NULL == allocTag) { //err msg IOLog("LULU ERROR: OSMalloc_Tagalloc() failed\n"); //bail goto bail; } //alloc // ->rule locks, etc if(true != initRules()) { //err msg IOLog("LULU ERROR: failed to init rules/locks\n"); //bail goto bail; } //init shared data queue sharedDataQueue = IOSharedDataQueue::withCapacity(sizeof(firewallEvent) * (MAX_FIREWALL_EVENTS + DATA_QUEUE_ENTRY_HEADER_SIZE)); if(NULL == sharedDataQueue) { //bail goto bail; } //get memory descriptor sharedMemoryDescriptor = sharedDataQueue->getMemoryDescriptor(); if(NULL == sharedMemoryDescriptor) { //bail goto bail; } //register service // allows clients to connect registerService(); //dbg msg IOLog("LULU: registered service %s\n", LULU_SERVICE_NAME); //set user class setProperty("IOUserClientClass", LULU_USER_CLIENT_CLASS); //init broadcast if(true != initBroadcast()) { //err msg IOLog("LULU ERROR: initBroadcast() failed\n"); //bail goto bail; } //all happy result = true; bail: return result; }