jameschennerd commited on
Commit
3fd0056
·
verified ·
1 Parent(s): 21914b2

Delete fnptr-dynamic-call.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. fnptr-dynamic-call.md +0 -838
fnptr-dynamic-call.md DELETED
@@ -1,838 +0,0 @@
1
- # Example 1
2
-
3
- ## Callsite
4
-
5
- */home/yuanting/work/icall-benchmarks/llm/redis-stable/src/module.c:12148:9*
6
-
7
- fnptr: *onload*
8
-
9
- targets: RedisModule_OnLoad
10
-
11
- ## Related Code Snippets
12
-
13
- ```c
14
- handle = dlopen(path,RTLD_NOW|RTLD_LOCAL);
15
- if (handle == NULL) {
16
- serverLog(LL_WARNING, "Module %s failed to load: %s", path, dlerror());
17
- return C_ERR;
18
- }
19
- onload = (int (*)(void *, void **, int))(unsigned long) dlsym(handle,"RedisModule_OnLoad");
20
- if (onload == NULL) {
21
- dlclose(handle);
22
- serverLog(LL_WARNING,
23
- "Module %s does not export RedisModule_OnLoad() "
24
- "symbol. Module not loaded.",path);
25
- return C_ERR;
26
- }
27
- RedisModuleCtx ctx;
28
- moduleCreateContext(&ctx, NULL, REDISMODULE_CTX_TEMP_CLIENT); /* We pass NULL since we don't have a module yet. */
29
- if (onload((void*)&ctx,module_argv,module_argc) == REDISMODULE_ERR) {
30
- serverLog(LL_WARNING,
31
- "Module %s initialization failed. Module not loaded",path);
32
- if (ctx.module) {
33
- moduleUnregisterCommands(ctx.module);
34
- moduleUnregisterSharedAPI(ctx.module);
35
- moduleUnregisterUsedAPI(ctx.module);
36
- moduleRemoveConfigs(ctx.module);
37
- moduleUnregisterAuthCBs(ctx.module);
38
- moduleFreeModuleStructure(ctx.module);
39
- }
40
- moduleFreeContext(&ctx);
41
- dlclose(handle);
42
- return C_ERR;
43
- }
44
- ```
45
-
46
- # Example 2
47
-
48
- ## Callsite
49
-
50
- */home/yuanting/work/icall-benchmarks/llm/openssh-build/../openssh-9.6p1/ssh-sk.c:148:12*
51
-
52
- fnptr: *ret->sk_api_version*
53
-
54
- targets: sk_api_version
55
-
56
- ## Related Code Snippets
57
-
58
- ```c
59
- if ((ret->dlhandle = dlopen(path, RTLD_NOW)) == NULL)
60
- fatal("Provider \"%s\" dlopen failed: %s", path, dlerror());
61
- if ((ret->sk_api_version = dlsym(ret->dlhandle,
62
- "sk_api_version")) == NULL) {
63
- error("Provider \"%s\" dlsym(sk_api_version) failed: %s",
64
- path, dlerror());
65
- goto fail;
66
- }
67
- version = ret->sk_api_version();
68
- ```
69
-
70
- # Example 3
71
-
72
- ## Callsite
73
-
74
- */home/yuanting/work/icall-benchmarks/llm/ffmpeg-6.1.1/libavcodec/omx.c:177:5*
75
-
76
- fnptr: *omx_context->ptr_Init*
77
-
78
- targets: OMX_Init
79
-
80
- ## Related Code Snippets
81
-
82
- ```c
83
- static av_cold void *dlsym_prefixed(void *handle, const char *symbol, const char *prefix)
84
- {
85
- char buf[50];
86
- snprintf(buf, sizeof(buf), "%s%s", prefix ? prefix : "", symbol);
87
- return dlsym(handle, buf);
88
- }
89
- ```
90
-
91
- ```c
92
- static av_cold int omx_try_load(OMXContext *s, void *logctx,
93
- const char *libname, const char *prefix,
94
- const char *libname2)
95
- {
96
- ...
97
- s->ptr_Init = dlsym_prefixed(s->lib, "OMX_Init", prefix);
98
- ...
99
- }
100
- ```
101
-
102
- ```c
103
- static av_cold OMXContext *omx_init(void *logctx, const char *libname, const char *prefix)
104
- {
105
- static const char * const libnames[] = {
106
- #if CONFIG_OMX_RPI
107
- "/opt/vc/lib/libopenmaxil.so", "/opt/vc/lib/libbcm_host.so",
108
- #else
109
- "libOMX_Core.so", NULL,
110
- "libOmxCore.so", NULL,
111
- #endif
112
- NULL
113
- };
114
- const char* const* nameptr;
115
- int ret = AVERROR_ENCODER_NOT_FOUND;
116
- OMXContext *omx_context;
117
-
118
- omx_context = av_mallocz(sizeof(*omx_context));
119
- if (!omx_context)
120
- return NULL;
121
- if (libname) {
122
- ret = omx_try_load(omx_context, logctx, libname, prefix, NULL);
123
- if (ret < 0) {
124
- av_free(omx_context);
125
- return NULL;
126
- }
127
- } else {
128
- for (nameptr = libnames; *nameptr; nameptr += 2)
129
- if (!(ret = omx_try_load(omx_context, logctx, nameptr[0], prefix, nameptr[1])))
130
- break;
131
- if (!*nameptr) {
132
- av_free(omx_context);
133
- return NULL;
134
- }
135
- }
136
-
137
- if (omx_context->host_init)
138
- omx_context->host_init();
139
- omx_context->ptr_Init();
140
- return omx_context;
141
- }
142
- ```
143
-
144
- ```c
145
- static av_cold int omx_encode_init(AVCodecContext *avctx)
146
- {
147
- OMXCodecContext *s = avctx->priv_data;
148
- ...
149
-
150
- /* cleanup relies on the mutexes/conditions being initialized first. */
151
- ret = ff_pthread_init(s, omx_codec_context_offsets);
152
- if (ret < 0)
153
- return ret;
154
- s->omx_context = omx_init(avctx, s->libname, s->libprefix);
155
- ...
156
- }
157
- ```
158
-
159
- ```c
160
- typedef struct OMXCodecContext {
161
- const AVClass *class;
162
- char *libname;
163
- char *libprefix;
164
- ...
165
- } OMXCodecContext;
166
- ```
167
-
168
- ```c
169
- const FFCodec ff_h264_omx_encoder = {
170
- .p.name = "h264_omx",
171
- CODEC_LONG_NAME("OpenMAX IL H.264 video encoder"),
172
- .p.type = AVMEDIA_TYPE_VIDEO,
173
- .p.id = AV_CODEC_ID_H264,
174
- .priv_data_size = sizeof(OMXCodecContext),
175
- .init = omx_encode_init,
176
- FF_CODEC_ENCODE_CB(omx_encode_frame),
177
- .close = omx_encode_end,
178
- .p.pix_fmts = omx_encoder_pix_fmts,
179
- .p.capabilities = AV_CODEC_CAP_DELAY,
180
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
181
- .p.priv_class = &omx_h264enc_class,
182
- };
183
- ```
184
-
185
- ```c
186
- static const AVClass omx_h264enc_class = {
187
- .class_name = "h264_omx",
188
- .item_name = av_default_item_name,
189
- .option = options,
190
- .version = LIBAVUTIL_VERSION_INT,
191
- };
192
- ```
193
-
194
- ```c
195
- static const AVOption options[] = {
196
- { "omx_libname", "OpenMAX library name", OFFSET(libname), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
197
- { "omx_libprefix", "OpenMAX library prefix", OFFSET(libprefix), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
198
- { "zerocopy", "Try to avoid copying input frames if possible", OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = CONFIG_OMX_RPI }, 0, 1, VE },
199
- { "profile", "Set the encoding profile", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, AV_PROFILE_H264_HIGH, VE, "profile" },
200
- { "baseline", "", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PROFILE_H264_BASELINE }, 0, 0, VE, "profile" },
201
- { "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PROFILE_H264_MAIN }, 0, 0, VE, "profile" },
202
- { "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PROFILE_H264_HIGH }, 0, 0, VE, "profile" },
203
- { NULL }
204
- };
205
- ```
206
-
207
- # Example 4
208
-
209
- ## Callsite
210
-
211
- */home/yuanting/work/icall-benchmarks/llm/wrk-4.2.0/obj/openssl-1.1.1i/crypto/engine/eng_dyn.c:480:10*
212
-
213
- fnptr: *ctx->bind_engine*
214
-
215
- targets: bind_engine
216
-
217
- ## Related Code Snippets
218
-
219
- ```c
220
- void engine_load_dynamic_int(void)
221
- {
222
- ENGINE *toadd = engine_dynamic();
223
- if (!toadd)
224
- return;
225
- ENGINE_add(toadd);
226
- /*
227
- * If the "add" worked, it gets a structural reference. So either way, we
228
- * release our just-created reference.
229
- */
230
- ENGINE_free(toadd);
231
- /*
232
- * If the "add" didn't work, it was probably a conflict because it was
233
- * already added (eg. someone calling ENGINE_load_blah then calling
234
- * ENGINE_load_builtin_engines() perhaps).
235
- */
236
- ERR_clear_error();
237
- }
238
-
239
- ```
240
-
241
- ```c
242
- static ENGINE *engine_dynamic(void)
243
- {
244
- ENGINE *ret = ENGINE_new();
245
- if (ret == NULL)
246
- return NULL;
247
- if (!ENGINE_set_id(ret, engine_dynamic_id) ||
248
- !ENGINE_set_name(ret, engine_dynamic_name) ||
249
- !ENGINE_set_init_function(ret, dynamic_init) ||
250
- !ENGINE_set_finish_function(ret, dynamic_finish) ||
251
- !ENGINE_set_ctrl_function(ret, dynamic_ctrl) ||
252
- !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) ||
253
- !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns)) {
254
- ENGINE_free(ret);
255
- return NULL;
256
- }
257
- return ret;
258
- }
259
- ```
260
-
261
- ```c
262
- /* Add another "ENGINE" type into the list. */
263
- int ENGINE_add(ENGINE *e)
264
- {
265
- int to_return = 1;
266
- if (e == NULL) {
267
- ENGINEerr(ENGINE_F_ENGINE_ADD, ERR_R_PASSED_NULL_PARAMETER);
268
- return 0;
269
- }
270
- if ((e->id == NULL) || (e->name == NULL)) {
271
- ENGINEerr(ENGINE_F_ENGINE_ADD, ENGINE_R_ID_OR_NAME_MISSING);
272
- return 0;
273
- }
274
- CRYPTO_THREAD_write_lock(global_engine_lock);
275
- if (!engine_list_add(e)) {
276
- ENGINEerr(ENGINE_F_ENGINE_ADD, ENGINE_R_INTERNAL_LIST_ERROR);
277
- to_return = 0;
278
- }
279
- CRYPTO_THREAD_unlock(global_engine_lock);
280
- return to_return;
281
- }
282
- ```
283
-
284
- ```c
285
- ENGINE *ENGINE_by_id(const char *id)
286
- {
287
- ENGINE *iterator;
288
- char *load_dir = NULL;
289
- if (id == NULL) {
290
- ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_PASSED_NULL_PARAMETER);
291
- return NULL;
292
- }
293
- if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
294
- ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_MALLOC_FAILURE);
295
- return NULL;
296
- }
297
-
298
- CRYPTO_THREAD_write_lock(global_engine_lock);
299
- iterator = engine_list_head;
300
- while (iterator && (strcmp(id, iterator->id) != 0))
301
- iterator = iterator->next;
302
- if (iterator != NULL) {
303
- /*
304
- * We need to return a structural reference. If this is an ENGINE
305
- * type that returns copies, make a duplicate - otherwise increment
306
- * the existing ENGINE's reference count.
307
- */
308
- if (iterator->flags & ENGINE_FLAGS_BY_ID_COPY) {
309
- ENGINE *cp = ENGINE_new();
310
- if (cp == NULL)
311
- iterator = NULL;
312
- else {
313
- engine_cpy(cp, iterator);
314
- iterator = cp;
315
- }
316
- } else {
317
- iterator->struct_ref++;
318
- engine_ref_debug(iterator, 0, 1);
319
- }
320
- }
321
- CRYPTO_THREAD_unlock(global_engine_lock);
322
- if (iterator != NULL)
323
- return iterator;
324
- /*
325
- * Prevent infinite recursion if we're looking for the dynamic engine.
326
- */
327
- if (strcmp(id, "dynamic")) {
328
- if ((load_dir = ossl_safe_getenv("OPENSSL_ENGINES")) == NULL)
329
- load_dir = ENGINESDIR;
330
- iterator = ENGINE_by_id("dynamic");
331
- if (!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) ||
332
- !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) ||
333
- !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD",
334
- load_dir, 0) ||
335
- !ENGINE_ctrl_cmd_string(iterator, "LIST_ADD", "1", 0) ||
336
- !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0))
337
- goto notfound;
338
- return iterator;
339
- }
340
- notfound:
341
- ENGINE_free(iterator);
342
- ENGINEerr(ENGINE_F_ENGINE_BY_ID, ENGINE_R_NO_SUCH_ENGINE);
343
- ERR_add_error_data(2, "id=", id);
344
- return NULL;
345
- /* EEK! Experimental code ends */
346
- }
347
- ```
348
-
349
- ```c
350
- int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
351
- int cmd_optional)
352
- {
353
- int num, flags;
354
- long l;
355
- char *ptr;
356
-
357
- if (e == NULL || cmd_name == NULL) {
358
- ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, ERR_R_PASSED_NULL_PARAMETER);
359
- return 0;
360
- }
361
- if (e->ctrl == NULL
362
- || (num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME,
363
- 0, (void *)cmd_name, NULL)) <= 0) {
364
- }
365
- }
366
- ```
367
-
368
- ```c
369
- int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f)
370
- {
371
- e->ctrl = ctrl_f;
372
- return 1;
373
- }
374
- ```
375
-
376
- ```c
377
- int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
378
- {
379
- int ctrl_exists, ref_exists;
380
- if (e == NULL) {
381
- ENGINEerr(ENGINE_F_ENGINE_CTRL, ERR_R_PASSED_NULL_PARAMETER);
382
- return 0;
383
- }
384
- CRYPTO_THREAD_write_lock(global_engine_lock);
385
- ref_exists = ((e->struct_ref > 0) ? 1 : 0);
386
- CRYPTO_THREAD_unlock(global_engine_lock);
387
- ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
388
- if (!ref_exists) {
389
- ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_REFERENCE);
390
- return 0;
391
- }
392
- /*
393
- * Intercept any "root-level" commands before trying to hand them on to
394
- * ctrl() handlers.
395
- */
396
- switch (cmd) {
397
- case ENGINE_CTRL_HAS_CTRL_FUNCTION:
398
- return ctrl_exists;
399
- case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
400
- case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
401
- case ENGINE_CTRL_GET_CMD_FROM_NAME:
402
- case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
403
- case ENGINE_CTRL_GET_NAME_FROM_CMD:
404
- case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
405
- case ENGINE_CTRL_GET_DESC_FROM_CMD:
406
- case ENGINE_CTRL_GET_CMD_FLAGS:
407
- if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
408
- return int_ctrl_helper(e, cmd, i, p, f);
409
- if (!ctrl_exists) {
410
- ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION);
411
- /*
412
- * For these cmd-related functions, failure is indicated by a -1
413
- * return value (because 0 is used as a valid return in some
414
- * places).
415
- */
416
- return -1;
417
- }
418
- default:
419
- break;
420
- }
421
- /* Anything else requires a ctrl() handler to exist. */
422
- if (!ctrl_exists) {
423
- ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION);
424
- return 0;
425
- }
426
- return e->ctrl(e, cmd, i, p, f);
427
- }
428
- ```
429
-
430
- ```c
431
- static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
432
- {
433
- dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
434
- switch (cmd) {
435
- case DYNAMIC_CMD_LOAD:
436
- return dynamic_load(e, ctx);
437
- }
438
- }
439
- ```
440
-
441
- ```c
442
- /*
443
- * This function retrieves the context structure from an ENGINE's "ex_data",
444
- * or if it doesn't exist yet, sets it up.
445
- */
446
- static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e)
447
- {
448
- dynamic_data_ctx *ctx;
449
- if (dynamic_ex_data_idx < 0) {
450
- /*
451
- * Create and register the ENGINE ex_data, and associate our "free"
452
- * function with it to ensure any allocated contexts get freed when
453
- * an ENGINE goes underground.
454
- */
455
- int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL,
456
- dynamic_data_ctx_free_func);
457
- if (new_idx == -1) {
458
- ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX, ENGINE_R_NO_INDEX);
459
- return NULL;
460
- }
461
- CRYPTO_THREAD_write_lock(global_engine_lock);
462
- /* Avoid a race by checking again inside this lock */
463
- if (dynamic_ex_data_idx < 0) {
464
- /* Good, someone didn't beat us to it */
465
- dynamic_ex_data_idx = new_idx;
466
- new_idx = -1;
467
- }
468
- CRYPTO_THREAD_unlock(global_engine_lock);
469
- /*
470
- * In theory we could "give back" the index here if (new_idx>-1), but
471
- * it's not possible and wouldn't gain us much if it were.
472
- */
473
- }
474
- ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx);
475
- /* Check if the context needs to be created */
476
- if ((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx))
477
- /* "set_data" will set errors if necessary */
478
- return NULL;
479
- return ctx;
480
- }
481
- ```
482
-
483
- ```c
484
- static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
485
- {
486
- dynamic_data_ctx *c = OPENSSL_zalloc(sizeof(*c));
487
- int ret = 1;
488
-
489
- if (c == NULL) {
490
- ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE);
491
- return 0;
492
- }
493
- c->dirs = sk_OPENSSL_STRING_new_null();
494
- if (c->dirs == NULL) {
495
- ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE);
496
- OPENSSL_free(c);
497
- return 0;
498
- }
499
- c->DYNAMIC_F1 = "v_check";
500
- c->DYNAMIC_F2 = "bind_engine";
501
- c->dir_load = 1;
502
- CRYPTO_THREAD_write_lock(global_engine_lock);
503
- if ((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
504
- dynamic_ex_data_idx))
505
- == NULL) {
506
- /* Good, we're the first */
507
- ret = ENGINE_set_ex_data(e, dynamic_ex_data_idx, c);
508
- if (ret) {
509
- *ctx = c;
510
- c = NULL;
511
- }
512
- }
513
- CRYPTO_THREAD_unlock(global_engine_lock);
514
- /*
515
- * If we lost the race to set the context, c is non-NULL and *ctx is the
516
- * context of the thread that won.
517
- */
518
- if (c)
519
- sk_OPENSSL_STRING_free(c->dirs);
520
- OPENSSL_free(c);
521
- return ret;
522
- }
523
- ```
524
-
525
- ```c
526
- static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
527
- {
528
- ENGINE cpy;
529
- dynamic_fns fns;
530
-
531
- if (ctx->dynamic_dso == NULL)
532
- ctx->dynamic_dso = DSO_new();
533
- if (ctx->dynamic_dso == NULL)
534
- return 0;
535
- if (!ctx->DYNAMIC_LIBNAME) {
536
- if (!ctx->engine_id)
537
- return 0;
538
- DSO_ctrl(ctx->dynamic_dso, DSO_CTRL_SET_FLAGS,
539
- DSO_FLAG_NAME_TRANSLATION_EXT_ONLY, NULL);
540
- ctx->DYNAMIC_LIBNAME =
541
- DSO_convert_filename(ctx->dynamic_dso, ctx->engine_id);
542
- }
543
- if (!int_load(ctx)) {
544
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD, ENGINE_R_DSO_NOT_FOUND);
545
- DSO_free(ctx->dynamic_dso);
546
- ctx->dynamic_dso = NULL;
547
- return 0;
548
- }
549
- /* We have to find a bind function otherwise it'll always end badly */
550
- if (!
551
- (ctx->bind_engine =
552
- (dynamic_bind_engine) DSO_bind_func(ctx->dynamic_dso,
553
- ctx->DYNAMIC_F2))) {
554
- ctx->bind_engine = NULL;
555
- DSO_free(ctx->dynamic_dso);
556
- ctx->dynamic_dso = NULL;
557
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD, ENGINE_R_DSO_FAILURE);
558
- return 0;
559
- }
560
- /* Do we perform version checking? */
561
- if (!ctx->no_vcheck) {
562
- unsigned long vcheck_res = 0;
563
- /*
564
- * Now we try to find a version checking function and decide how to
565
- * cope with failure if/when it fails.
566
- */
567
- ctx->v_check =
568
- (dynamic_v_check_fn) DSO_bind_func(ctx->dynamic_dso,
569
- ctx->DYNAMIC_F1);
570
- if (ctx->v_check)
571
- vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION);
572
- /*
573
- * We fail if the version checker veto'd the load *or* if it is
574
- * deferring to us (by returning its version) and we think it is too
575
- * old.
576
- */
577
- if (vcheck_res < OSSL_DYNAMIC_OLDEST) {
578
- /* Fail */
579
- ctx->bind_engine = NULL;
580
- ctx->v_check = NULL;
581
- DSO_free(ctx->dynamic_dso);
582
- ctx->dynamic_dso = NULL;
583
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
584
- ENGINE_R_VERSION_INCOMPATIBILITY);
585
- return 0;
586
- }
587
- }
588
- /*
589
- * First binary copy the ENGINE structure so that we can roll back if the
590
- * hand-over fails
591
- */
592
- memcpy(&cpy, e, sizeof(ENGINE));
593
- /*
594
- * Provide the ERR, "ex_data", memory, and locking callbacks so the
595
- * loaded library uses our state rather than its own. FIXME: As noted in
596
- * engine.h, much of this would be simplified if each area of code
597
- * provided its own "summary" structure of all related callbacks. It
598
- * would also increase opaqueness.
599
- */
600
- fns.static_state = ENGINE_get_static_state();
601
- CRYPTO_get_mem_functions(&fns.mem_fns.malloc_fn, &fns.mem_fns.realloc_fn,
602
- &fns.mem_fns.free_fn);
603
- /*
604
- * Now that we've loaded the dynamic engine, make sure no "dynamic"
605
- * ENGINE elements will show through.
606
- */
607
- engine_set_all_null(e);
608
-
609
- /* Try to bind the ENGINE onto our own ENGINE structure */
610
- if (!ctx->bind_engine(e, ctx->engine_id, &fns)) {
611
- ctx->bind_engine = NULL;
612
- ctx->v_check = NULL;
613
- DSO_free(ctx->dynamic_dso);
614
- ctx->dynamic_dso = NULL;
615
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD, ENGINE_R_INIT_FAILED);
616
- /* Copy the original ENGINE structure back */
617
- memcpy(e, &cpy, sizeof(ENGINE));
618
- return 0;
619
- }
620
- /* Do we try to add this ENGINE to the internal list too? */
621
- if (ctx->list_add_value > 0) {
622
- if (!ENGINE_add(e)) {
623
- /* Do we tolerate this or fail? */
624
- if (ctx->list_add_value > 1) {
625
- /*
626
- * Fail - NB: By this time, it's too late to rollback, and
627
- * trying to do so allows the bind_engine() code to have
628
- * created leaks. We just have to fail where we are, after
629
- * the ENGINE has changed.
630
- */
631
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
632
- ENGINE_R_CONFLICTING_ENGINE_ID);
633
- return 0;
634
- }
635
- /* Tolerate */
636
- ERR_clear_error();
637
- }
638
- }
639
- return 1;
640
- }
641
- ```
642
-
643
- ```c
644
- static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
645
- {
646
- dynamic_data_ctx *c = OPENSSL_zalloc(sizeof(*c));
647
- int ret = 1;
648
-
649
- if (c == NULL) {
650
- ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE);
651
- return 0;
652
- }
653
- c->dirs = sk_OPENSSL_STRING_new_null();
654
- if (c->dirs == NULL) {
655
- ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE);
656
- OPENSSL_free(c);
657
- return 0;
658
- }
659
- c->DYNAMIC_F1 = "v_check";
660
- c->DYNAMIC_F2 = "bind_engine";
661
- c->dir_load = 1;
662
- CRYPTO_THREAD_write_lock(global_engine_lock);
663
- if ((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
664
- dynamic_ex_data_idx))
665
- == NULL) {
666
- /* Good, we're the first */
667
- ret = ENGINE_set_ex_data(e, dynamic_ex_data_idx, c);
668
- if (ret) {
669
- *ctx = c;
670
- c = NULL;
671
- }
672
- }
673
- CRYPTO_THREAD_unlock(global_engine_lock);
674
- /*
675
- * If we lost the race to set the context, c is non-NULL and *ctx is the
676
- * context of the thread that won.
677
- */
678
- if (c)
679
- sk_OPENSSL_STRING_free(c->dirs);
680
- OPENSSL_free(c);
681
- return ret;
682
- }
683
- ```
684
-
685
- ```c
686
- DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
687
- {
688
- DSO_FUNC_TYPE ret = NULL;
689
-
690
- if ((dso == NULL) || (symname == NULL)) {
691
- DSOerr(DSO_F_DSO_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
692
- return NULL;
693
- }
694
- if (dso->meth->dso_bind_func == NULL) {
695
- DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_UNSUPPORTED);
696
- return NULL;
697
- }
698
- if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) {
699
- DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_SYM_FAILURE);
700
- return NULL;
701
- }
702
- /* Success */
703
- return ret;
704
- }
705
- ```
706
-
707
- ```c
708
- struct dso_meth_st {
709
- const char *name;
710
- /*
711
- * Loads a shared library, NB: new DSO_METHODs must ensure that a
712
- * successful load populates the loaded_filename field, and likewise a
713
- * successful unload OPENSSL_frees and NULLs it out.
714
- */
715
- int (*dso_load) (DSO *dso);
716
- /* Unloads a shared library */
717
- int (*dso_unload) (DSO *dso);
718
- /*
719
- * Binds a function - assumes a return type of DSO_FUNC_TYPE. This should
720
- * be cast to the real function prototype by the caller. Platforms that
721
- * don't have compatible representations for different prototypes (this
722
- * is possible within ANSI C) are highly unlikely to have shared
723
- * libraries at all, let alone a DSO_METHOD implemented for them.
724
- */
725
- DSO_FUNC_TYPE (*dso_bind_func) (DSO *dso, const char *symname);
726
- /*
727
- * The generic (yuck) "ctrl()" function. NB: Negative return values
728
- * (rather than zero) indicate errors.
729
- */
730
- long (*dso_ctrl) (DSO *dso, int cmd, long larg, void *parg);
731
- /*
732
- * The default DSO_METHOD-specific function for converting filenames to a
733
- * canonical native form.
734
- */
735
- DSO_NAME_CONVERTER_FUNC dso_name_converter;
736
- /*
737
- * The default DSO_METHOD-specific function for converting filenames to a
738
- * canonical native form.
739
- */
740
- DSO_MERGER_FUNC dso_merger;
741
- /* [De]Initialisation handlers. */
742
- int (*init) (DSO *dso);
743
- int (*finish) (DSO *dso);
744
- /* Return pathname of the module containing location */
745
- int (*pathbyaddr) (void *addr, char *path, int sz);
746
- /* Perform global symbol lookup, i.e. among *all* modules */
747
- void *(*globallookup) (const char *symname);
748
- };
749
- ```
750
-
751
- # Example 5
752
-
753
- ## Callsite
754
-
755
- */home/yuanting/work/icall-benchmarks/llm/openssh-build/../openssh-9.6p1/ssh-sk.c:535:11*
756
-
757
- fnptr: *skp->sk_enroll*
758
-
759
- targets: sk_enroll, ssh_sk_enroll
760
-
761
- ## Related Code Snippets
762
-
763
- ```c
764
- int
765
- sshsk_enroll(int type, const char *provider_path, const char *device,
766
- const char *application, const char *userid, uint8_t flags,
767
- const char *pin, struct sshbuf *challenge_buf,
768
- struct sshkey **keyp, struct sshbuf *attest)
769
- {
770
- if ((skp = sshsk_open(provider_path)) == NULL) {
771
- r = SSH_ERR_INVALID_FORMAT; /* XXX sshsk_open return code? */
772
- goto out;
773
- }
774
- /* XXX validate flags? */
775
- /* enroll key */
776
- if ((r = skp->sk_enroll(alg, challenge, challenge_len, application,
777
- flags, pin, opts, &resp)) != 0) {
778
- debug_f("provider \"%s\" failure %d", provider_path, r);
779
- r = skerr_to_ssherr(r);
780
- goto out;
781
- }
782
- out:
783
- return r;
784
- }
785
- ```
786
-
787
- ```c
788
- static struct sshsk_provider *
789
- sshsk_open(const char *path)
790
- {
791
- struct sshsk_provider *ret = NULL;
792
- uint32_t version;
793
-
794
- if (path == NULL || *path == '\0') {
795
- error("No FIDO SecurityKeyProvider specified");
796
- return NULL;
797
- }
798
- if ((ret = calloc(1, sizeof(*ret))) == NULL) {
799
- error_f("calloc failed");
800
- return NULL;
801
- }
802
- if ((ret->path = strdup(path)) == NULL) {
803
- error_f("strdup failed");
804
- goto fail;
805
- }
806
- /* Skip the rest if we're using the linked in middleware */
807
- if (strcasecmp(ret->path, "internal") == 0) {
808
- #ifdef ENABLE_SK_INTERNAL
809
- ret->sk_enroll = ssh_sk_enroll;
810
- ret->sk_sign = ssh_sk_sign;
811
- ret->sk_load_resident_keys = ssh_sk_load_resident_keys;
812
- return ret;
813
- #else
814
- error("internal security key support not enabled");
815
- goto fail;
816
- #endif
817
- }
818
- if ((ret->dlhandle = dlopen(path, RTLD_NOW)) == NULL)
819
- fatal("Provider \"%s\" dlopen failed: %s", path, dlerror());
820
- if ((ret->sk_enroll = dlsym(ret->dlhandle, "sk_enroll")) == NULL) {
821
- error("Provider %s dlsym(sk_enroll) failed: %s",
822
- path, dlerror());
823
- goto fail;
824
- }
825
- /* success */
826
- return ret;
827
- fail:
828
- sshsk_free(ret);
829
- return NULL;
830
- }
831
- ```
832
-
833
- ```c
834
- int ssh_sk_enroll(int alg, const uint8_t *challenge,
835
- size_t challenge_len, const char *application, uint8_t flags,
836
- const char *pin, struct sk_option **opts,
837
- struct sk_enroll_response **enroll_response);
838
- ```