int audit_objopen(Rt_map *clmp, Rt_map *nlmp) { Lmid_t lmid = get_linkmap_id(LIST(nlmp)); int appl = 0, respond = 1, ndx = 0; uint_t clients = 0; Audit_info * aip; /* * Determine the total number of audit libraries in use. This provides * the number of client structures required for this object. */ if (auditors) clients = auditors->ad_cnt; if (AUDITORS(clmp)) clients += AUDITORS(clmp)->ad_cnt; if ((nlmp != clmp) && AUDITORS(nlmp)) clients += AUDITORS(nlmp)->ad_cnt; /* * The initial allocation of the audit information structure includes * an array of audit clients, 1 per audit library presently available. * * --------------- * | ai_cnt | * Audit_info | ai_clients |------- * | ai_dynplts | | * |---------------| | * Audit_client | 1 |<------ * |---------------| * | 2 | * ......... */ if ((AUDINFO(nlmp) = aip = calloc(1, sizeof (Audit_info) + (sizeof (Audit_client) * clients))) == 0) return (0); aip->ai_cnt = clients; aip->ai_clients = (Audit_client *)((uintptr_t)aip + sizeof (Audit_info)); if ((rtld_flags & RT_FL_APPLIC) == 0) appl = rtld_flags |= RT_FL_APPLIC; if (auditors) respond = _audit_objopen(&(auditors->ad_list), nlmp, lmid, aip, &ndx); if (respond && AUDITORS(clmp)) respond = _audit_objopen(&(AUDITORS(clmp)->ad_list), nlmp, lmid, aip, &ndx); if (respond && (nlmp != clmp) && AUDITORS(nlmp)) respond = _audit_objopen(&(AUDITORS(nlmp)->ad_list), nlmp, lmid, aip, &ndx); if (appl) rtld_flags &= ~RT_FL_APPLIC; return (respond); }
int audit_objopen(Rt_map *clmp, Rt_map *nlmp) { Lmid_t lmid = get_linkmap_id(LIST(nlmp)); int respond = 1, ndx = 0; uint_t rtldflags; uint_t clients = 0; Audit_info *aip; if (rt_critical()) return (respond); /* * Determine the number of auditors that can receive information * regarding this object. This provides the number of client * structures required for this object. */ if (auditors) clients = auditors->ad_cnt; if (AUDITORS(clmp)) clients += AUDITORS(clmp)->ad_cnt; if ((nlmp != clmp) && AUDITORS(nlmp)) clients += AUDITORS(nlmp)->ad_cnt; /* * Allocate an audit information structure. Each audited object * maintains a AUDINFO() structure. As this structure can only be * created once all auditors are loaded, a client count can now be * computed. * * The allocation of the audit information structure includes an array * of audit clients, 1 per audit library that has been loaded. * * --------------- * | ai_cnt | * Audit_info | ai_clients |------- * | ai_dynplts | | * |---------------| | * Audit_client | 1 |<------ * |---------------| * | 2 | * ......... */ if ((AUDINFO(nlmp) = aip = calloc(1, sizeof (Audit_info) + (sizeof (Audit_client) * clients))) == NULL) return (0); aip->ai_cnt = clients; aip->ai_clients = (Audit_client *)((uintptr_t)aip + sizeof (Audit_info)); APPLICATION_ENTER(rtldflags); if (auditors) respond = _audit_objopen(auditors->ad_list, nlmp, lmid, aip, &ndx); if (respond && AUDITORS(clmp)) respond = _audit_objopen(AUDITORS(clmp)->ad_list, nlmp, lmid, aip, &ndx); if (respond && (nlmp != clmp) && AUDITORS(nlmp)) respond = _audit_objopen(AUDITORS(nlmp)->ad_list, nlmp, lmid, aip, &ndx); APPLICATION_RETURN(rtldflags); return (respond); }
/* * la_objopen() caller for the head link-map. Global auditors, or an auditor * started from the object that heads a link-map list (typically the dynamic * executable), are passed to la_objopen(). However, local auditors can * provide activity and preinit events, and for these events, a cookie * representing the head link-map list object is expected. This routine obtains * these cookies from the link-map list lm_cookies element. This element * ensures all clients of the same auditor use the same cookie. * * Although a local auditor will get an la_objopen() call for the object that * heads the link-map list of the object being audited, the auditor is not * permitted to request binding information for this head object. The head * object has already been in existence, and bindings may have been resolved * with it. This local auditor is coming into existence too late, and thus we * don't allow any bindings to be caught at all. */ static int _audit_add_head(Rt_map *clmp, Rt_map *hlmp, int preinit, int activity) { Lm_list *clml = LIST(clmp); Lmid_t lmid = get_linkmap_id(clml); Audit_list *alp; Aliste idx; int save = 0; for (APLIST_TRAVERSE(AUDITORS(clmp)->ad_list, idx, alp)) { Audit_client *acp; Rt_map *almp = alp->al_lmp; Lm_list *alml = LIST(almp); uintptr_t *cookie; uint_t rtldflags; /* * Ensure this local auditor isn't already in existence as an * auditor for the head of the link-map list. If it is, then * this auditor will have already receive preinit and activity * events. */ if (AUDITORS(hlmp) && _audit_used_by_head(hlmp, almp)) continue; /* * Create a cookie that represents the object that heads the * link-map list. If the cookie already exists, then this * auditor has already been established for another objects * local auditing. In this case, do not issue a la_objopen() * or la_activity() event, as these will have already occurred. */ if ((acp = _audit_get_head_client(clml->lm_head, almp)) != NULL) continue; if ((acp = _audit_create_head_client(clml->lm_head, almp)) == NULL) return (0); cookie = &(acp->ac_cookie); save++; /* * Call the la_objopen() if available. */ if (alp->al_objopen) { uint_t flags; DBG_CALL(Dbg_audit_objopen(clml, DBG_AUD_CALL, alp->al_libname, NAME(hlmp), 0, FALSE)); APPLICATION_ENTER(rtldflags); leave(alml, thr_flg_reenter); flags = (*alp->al_objopen)((Link_map *)hlmp, lmid, cookie); (void) enter(thr_flg_reenter); APPLICATION_RETURN(rtldflags); if (flags) { DBG_CALL(Dbg_audit_objopen(clml, DBG_AUD_RET, alp->al_libname, NAME(hlmp), flags, TRUE)); } } /* * Call the la_activity() if available. */ if (alp->al_activity) { alml->lm_flags |= LML_FLG_AUDITNOTIFY; clml->lm_flags |= LML_FLG_ACTAUDIT; DBG_CALL(Dbg_audit_activity(clml, alp->al_libname, NAME(clml->lm_head), LA_ACT_ADD)); APPLICATION_ENTER(rtldflags); leave(alml, thr_flg_reenter); (*alp->al_activity)(cookie, LA_ACT_ADD); (void) enter(thr_flg_reenter); APPLICATION_RETURN(rtldflags); } } /* * If new head link-map cookies have been generated, then maintain * any preinit and/or activity requirements. */ if (save) { if (preinit && (aplist_append(&aud_preinit, clmp, AL_CNT_AUDITORS) == NULL)) return (0); if (activity && (aplist_append(&aud_activity, clmp, AL_CNT_AUDITORS) == NULL)) return (0); } return (1); }