ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

NTSTATUS NTAPI NtFindAtom ( IN PWSTR  AtomName,
IN ULONG  AtomNameLength,
OUT PRTL_ATOM Atom   
)

Definition at line 239 of file atom.c.

Referenced by InternalFindAtom().

{
    PRTL_ATOM_TABLE AtomTable = ExpGetGlobalAtomTable();
    NTSTATUS Status;
    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
    LPWSTR CapturedName = NULL;
    ULONG CapturedSize;
    RTL_ATOM SafeAtom;
    PAGED_CODE();

    /* Check for the table */
    if (AtomTable == NULL) return STATUS_ACCESS_DENIED;

    /* Check for valid name */
    if (AtomNameLength > (RTL_MAXIMUM_ATOM_LENGTH * sizeof(WCHAR)))
    {
        /* Fail */
        DPRINT1("Atom name too long\n");
        return STATUS_INVALID_PARAMETER;
    }
    
    /* Re-use the given name if kernel mode or no atom name */
    CapturedName = AtomName;

    /* Check if we're called from user-mode*/
    if (PreviousMode != KernelMode)
    {
        /* Enter SEH */
        _SEH2_TRY
        {
            /* Check if we have a name */
            if (AtomName)
            {
                /* Probe the atom */
                ProbeForRead(AtomName, AtomNameLength, sizeof(WCHAR));

                /* Allocate an aligned buffer + the null char */
                CapturedSize = ((AtomNameLength + sizeof(WCHAR)) &~
                                (sizeof(WCHAR) -1));
                CapturedName = ExAllocatePoolWithTag(PagedPool,
                                                     CapturedSize,
                                                     TAG_ATOM);
                if (!CapturedName)
                {
                    /* Fail the call */
                    Status = STATUS_INSUFFICIENT_RESOURCES;
                }
                else
                {
                    /* Copy the name and null-terminate it */
                    RtlCopyMemory(CapturedName, AtomName, AtomNameLength);
                    CapturedName[AtomNameLength / sizeof(WCHAR)] = UNICODE_NULL;
                }

                /* Probe the atom too */
                if (Atom) ProbeForWriteUshort(Atom);
            }
        }
        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
        {
            /* Return the exception code */
            _SEH2_YIELD(return _SEH2_GetExceptionCode());
        }
        _SEH2_END;
    }

    /* Call the runtime function */
    Status = RtlLookupAtomInAtomTable(AtomTable, CapturedName, &SafeAtom);
    if (NT_SUCCESS(Status) && (Atom))
    {
        /* Success and caller wants the atom back.. .enter SEH */
        _SEH2_TRY
        {
            /* Return the atom */
            *Atom = SafeAtom;
        }
        _SEH2_EXCEPT(ExSystemExceptionFilter())
        {
            Status = _SEH2_GetExceptionCode();
        }
        _SEH2_END;
    }

    /* If we captured anything, free it */
    if ((CapturedName) && (CapturedName != AtomName))
        ExFreePoolWithTag(CapturedName, TAG_ATOM);

    /* Return to caller */
    return Status;
}

Generated on Sun May 27 2012 05:11:08 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.