static void test_link_alloc2(void) { const char *o_tmpdir; /* try enough different sized base directory lengths so the code hits the different reallocations and tests for off-by-one errors */ string_t *basedir = t_str_new(256); str_append(basedir, cwd); str_append(basedir, "/"TEMP_DIRNAME); str_append_c(basedir, '/'); size_t base_len = str_len(basedir); o_tmpdir = tmpdir; /* path_normalize() initially allocates 128 bytes, so we'll test paths up to that length+1. */ unsigned char buf[128+1]; memset(buf, 'x', sizeof(buf)); for (size_t i = 1; i <= sizeof(buf); i++) { str_truncate(basedir, base_len); str_append_data(basedir, buf, i); tmpdir = str_c(basedir); (void)mkdir(str_c(basedir), 0700); create_links(tmpdir); test_link1(); test_link_loop(); } tmpdir = o_tmpdir; }
static void test_link_alloc(void) { #define COMPONENT_COMPONENT "/component-component" const char *o_tmpdir; /* idea here is to make sure component-component would optimally hit to the nearest_power value. it has to be big enough to cause requirement for allocation in t_realpath. */ string_t *basedir = t_str_new(256); str_append(basedir, cwd); str_append(basedir, "/"TEMP_DIRNAME); size_t len = nearest_power(I_MAX(127, str_len(basedir) + strlen(COMPONENT_COMPONENT) + 1)) - strlen(COMPONENT_COMPONENT); while(str_len(basedir) < len) { str_append(basedir, COMPONENT_COMPONENT); (void)mkdir(str_c(basedir), 0700); } o_tmpdir = tmpdir; tmpdir = str_c(basedir); create_links(tmpdir); test_link1(); test_link_loop(); tmpdir = o_tmpdir; }
static void test_init(void) { const char *error; test_assert(t_get_working_dir(&cwd, &error) == 0); tmpdir = t_strconcat(cwd, "/"TEMP_DIRNAME, NULL); test_cleanup(); if (mkdir(tmpdir, 0700) < 0) { i_fatal("mkdir: %m"); } create_links(tmpdir); }
void display_callback( void ){ delete nodes; nodes = new Node[ 0 ]; nodes_len = 0; create_random_nodes( &nodes, &nodes_len, 100 ); create_links( nodes, nodes_len, 100 ); glClearColor( 1.0, 0.0, 0.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); std::cout << "actual len: " << nodes_len << "\n\n\n\n\n"; glutSwapBuffers(); glutTimerFunc( frame_delay, render, 0 ); }
static bool construct(struct dc *dc, const struct dc_init_data *init_params) { struct dal_logger *logger; struct dc_context *dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL); struct bw_calcs_dceip *dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL); struct bw_calcs_vbios *dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL); #ifdef CONFIG_DRM_AMD_DC_DCN1_0 struct dcn_soc_bounding_box *dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL); struct dcn_ip_params *dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL); #endif enum dce_version dc_version = DCE_VERSION_UNKNOWN; if (!dc_dceip) { dm_error("%s: failed to create dceip\n", __func__); goto fail; } dc->bw_dceip = dc_dceip; if (!dc_vbios) { dm_error("%s: failed to create vbios\n", __func__); goto fail; } dc->bw_vbios = dc_vbios; #ifdef CONFIG_DRM_AMD_DC_DCN1_0 if (!dcn_soc) { dm_error("%s: failed to create dcn_soc\n", __func__); goto fail; } dc->dcn_soc = dcn_soc; if (!dcn_ip) { dm_error("%s: failed to create dcn_ip\n", __func__); goto fail; } dc->dcn_ip = dcn_ip; #endif if (!dc_ctx) { dm_error("%s: failed to create ctx\n", __func__); goto fail; } dc->current_state = dc_create_state(); if (!dc->current_state) { dm_error("%s: failed to create validate ctx\n", __func__); goto fail; } dc_ctx->cgs_device = init_params->cgs_device; dc_ctx->driver_context = init_params->driver; dc_ctx->dc = dc; dc_ctx->asic_id = init_params->asic_id; /* Create logger */ logger = dal_logger_create(dc_ctx, init_params->log_mask); if (!logger) { /* can *not* call logger. call base driver 'print error' */ dm_error("%s: failed to create Logger!\n", __func__); goto fail; } dc_ctx->logger = logger; dc->ctx = dc_ctx; dc->ctx->dce_environment = init_params->dce_environment; dc_version = resource_parse_asic_id(init_params->asic_id); dc->ctx->dce_version = dc_version; #if defined(CONFIG_DRM_AMD_DC_FBC) dc->ctx->fbc_gpu_addr = init_params->fbc_gpu_addr; #endif /* Resource should construct all asic specific resources. * This should be the only place where we need to parse the asic id */ if (init_params->vbios_override) dc_ctx->dc_bios = init_params->vbios_override; else { /* Create BIOS parser */ struct bp_init_data bp_init_data; bp_init_data.ctx = dc_ctx; bp_init_data.bios = init_params->asic_id.atombios_base_address; dc_ctx->dc_bios = dal_bios_parser_create( &bp_init_data, dc_version); if (!dc_ctx->dc_bios) { ASSERT_CRITICAL(false); goto fail; } dc_ctx->created_bios = true; } /* Create I2C AUX */ dc_ctx->i2caux = dal_i2caux_create(dc_ctx); if (!dc_ctx->i2caux) { ASSERT_CRITICAL(false); goto fail; } /* Create GPIO service */ dc_ctx->gpio_service = dal_gpio_service_create( dc_version, dc_ctx->dce_environment, dc_ctx); if (!dc_ctx->gpio_service) { ASSERT_CRITICAL(false); goto fail; } dc->res_pool = dc_create_resource_pool( dc, init_params->num_virtual_links, dc_version, init_params->asic_id); if (!dc->res_pool) goto fail; dc_resource_state_construct(dc, dc->current_state); if (!create_links(dc, init_params->num_virtual_links)) goto fail; allocate_dc_stream_funcs(dc); return true; fail: destruct(dc); return false; }
void start_daemon(int client) { // Launch the daemon, create new session, set proper context if (getuid() != UID_ROOT || getgid() != UID_ROOT) { fprintf(stderr, "Starting daemon requires root: %s\n", strerror(errno)); PLOGE("start daemon"); } switch (fork()) { case -1: PLOGE("fork"); case 0: break; default: return; } // First close the client, it's useless for us close(client); xsetsid(); setcon("u:r:su:s0"); umask(022); int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC); xdup2(fd, STDIN_FILENO); xdup2(fd, STDOUT_FILENO); xdup2(fd, STDERR_FILENO); close(fd); // Patch selinux with medium patch before we do anything load_policydb(SELINUX_POLICY); sepol_med_rules(); dump_policydb(SELINUX_LOAD); // Continue the larger patch in another thread, we will join later pthread_create(&sepol_patch, NULL, large_sepol_patch, NULL); struct sockaddr_un sun; fd = setup_socket(&sun); xbind(fd, (struct sockaddr*) &sun, sizeof(sun)); xlisten(fd, 10); // Change process name strcpy(argv0, "magisk_daemon"); // The root daemon should not do anything if an error occurs // It should stay intact under any circumstances err_handler = do_nothing; LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n"); // Unlock all blocks for rw unlock_blocks(); // Setup links under /sbin xmount(NULL, "/", NULL, MS_REMOUNT, NULL); create_links(NULL, "/sbin"); xchmod("/sbin", 0755); xmkdir("/magisk", 0755); xchmod("/magisk", 0755); xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL); // Loop forever to listen for requests while(1) { int *client = xmalloc(sizeof(int)); *client = xaccept4(fd, NULL, NULL, SOCK_CLOEXEC); pthread_t thread; xpthread_create(&thread, NULL, request_handler, client); // Detach the thread, we will never join it pthread_detach(thread); } }